Skip to content
Commits on Source (6)
PLUGIN := check_varnish
CLEANFILES := check_varnish
include ../common.mk
check_varnish:
set -e; for i in guess sub; do if [ ! -e src/config.$$i.bak ]; then cp src/config.$$i src/config.$$i.bak; fi; done
cp /usr/share/misc/config.* src
cd src && ./configure --prefix=/usr
make -C src
cp src/check_varnish $@
clean::
[ ! -f src/Makefile ] || make -C src distclean
set -e; for i in guess sub; do if [ -e src/config.$$i.bak ]; then mv src/config.$$i.bak src/config.$$i; fi; done
Uploaders: Bernd Zeimetz <bzed@debian.org>
Build-Depends: libvarnishapi-dev [!hurd-i386 !m68k], pkg-config, automake-1.15
Version: 258c486
Homepage: https://github.com/varnish/varnish-nagios
Watch: https://github.com/varnish/varnish-nagios <a class="commit-tease-sha"[^>]*>\s+([0-9a-f]+)\s+</a>
Description: plugin to monitor varnish instances
Copyright (c) 2007-2009 Linpro AS
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
varnish-nagios
\ No newline at end of file
Depends: varnish, systemd, dbus
Restrictions: needs-root, isolation-container
Tests: test_check_varnish
Copyright (c) 2007-2009 Linpro AS
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
# $Id$
libexec_PROGRAMS = check_varnish
check_varnish_SOURCES = check_varnish.c
check_varnish_CFLAGS = -include config.h ${VARNISHAPI_CFLAGS}
check_varnish_LDADD = ${VARNISHAPI_LIBS}
EXTRA_DIST = LICENSE autogen.sh
This diff is collapsed.
# check_varnish
A simple nagios check for varnish.
## Building
You will need the varnish source tree, or development packages in addition to autoconf, automake and pkg-config in order to build this:
./autogen.sh
./configure
make
This diff is collapsed.
#!/bin/sh
#
# $Id$
#
set -ex
. ./autogen.sh
# autoconf prior to 2.62 has issues with zsh 4.2 and newer
export CONFIG_SHELL=/bin/sh
./configure \
--enable-developer-warnings \
--enable-debugging-symbols \
--enable-dependency-tracking \
--enable-extra-developer-warnings \
--enable-stack-protector \
--enable-werror \
--prefix=/opt/varnish
#!/bin/sh
#
# $Id$
#
warn() {
echo "WARNING: $@" 1>&2
}
case `uname -s` in
Darwin)
LIBTOOLIZE=glibtoolize
;;
FreeBSD)
LIBTOOLIZE=libtoolize
if [ -d /usr/local/gnu-autotools/bin ] ; then
PATH=/usr/local/gnu-autotools/bin:${PATH}
export PATH
FIX_BROKEN_FREEBSD_PORTS="-I /usr/local/share/aclocal"
fi
;;
Linux)
LIBTOOLIZE=libtoolize
;;
esac
automake_version=$(automake --version | tr ' ' '\n' | egrep '^[0-9]\.[0-9a-z.-]+')
if [ -z "$automake_version" ] ; then
warn "unable to determine automake version"
else
case $automake_version in
0.*|1.[0-8]|1.[0-8][.-]*)
warn "automake ($automake_version) detected; 1.9 or newer recommended"
;;
*)
;;
esac
fi
set -ex
aclocal ${FIX_BROKEN_FREEBSD_PORTS}
$LIBTOOLIZE --copy --force
autoheader
automake --add-missing --copy --foreign
autoconf
This diff is collapsed.
This diff is collapsed.
# This file was generated by Autom4te Sat Mar 26 18:08:30 UTC 2016.
# It contains the lists of macros which have been traced.
# It can be safely removed.
@request = (
bless( [
'0',
1,
[
'/usr/share/autoconf'
],
[
'/usr/share/autoconf/autoconf/autoconf.m4f',
'-',
'/usr/share/aclocal-1.15/internal/ac-config-macro-dirs.m4',
'/usr/share/aclocal/libtool.m4',
'/usr/share/aclocal/ltargz.m4',
'/usr/share/aclocal/ltdl.m4',
'/usr/share/aclocal/ltoptions.m4',
'/usr/share/aclocal/ltsugar.m4',
'/usr/share/aclocal/ltversion.m4',
'/usr/share/aclocal/lt~obsolete.m4',
'/usr/share/aclocal/pkg.m4',
'/usr/share/aclocal/varnish-legacy.m4',
'/usr/share/aclocal-1.15/amversion.m4',
'/usr/share/aclocal-1.15/auxdir.m4',
'/usr/share/aclocal-1.15/cond.m4',
'/usr/share/aclocal-1.15/depend.m4',
'/usr/share/aclocal-1.15/depout.m4',
'/usr/share/aclocal-1.15/init.m4',
'/usr/share/aclocal-1.15/install-sh.m4',
'/usr/share/aclocal-1.15/lead-dot.m4',
'/usr/share/aclocal-1.15/make.m4',
'/usr/share/aclocal-1.15/missing.m4',
'/usr/share/aclocal-1.15/obsolete.m4',
'/usr/share/aclocal-1.15/options.m4',
'/usr/share/aclocal-1.15/prog-cc-c-o.m4',
'/usr/share/aclocal-1.15/runlog.m4',
'/usr/share/aclocal-1.15/sanity.m4',
'/usr/share/aclocal-1.15/silent.m4',
'/usr/share/aclocal-1.15/strip.m4',
'/usr/share/aclocal-1.15/substnot.m4',
'/usr/share/aclocal-1.15/tar.m4',
'configure.ac'
],
{
'LT_FUNC_ARGZ' => 1,
'LTDL_CONVENIENCE' => 1,
'AM_PROG_CC_STDC' => 1,
'_AM_DEPENDENCIES' => 1,
'AM_ENABLE_SHARED' => 1,
'AC_DEFUN_ONCE' => 1,
'_LT_COMPILER_BOILERPLATE' => 1,
'LT_AC_PROG_EGREP' => 1,
'AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE' => 1,
'AM_PROG_LIBTOOL' => 1,
'LTDL_INSTALLABLE' => 1,
'AC_LIBTOOL_CXX' => 1,
'AC_LIBTOOL_LANG_GCJ_CONFIG' => 1,
'LT_CMD_MAX_LEN' => 1,
'AM_INIT_AUTOMAKE' => 1,
'AC_LIB_LTDL' => 1,
'AC_LIBTOOL_SETUP' => 1,
'_AM_PROG_CC_C_O' => 1,
'LT_PROG_GO' => 1,
'_AC_PROG_LIBTOOL' => 1,
'_LT_CC_BASENAME' => 1,
'AU_DEFUN' => 1,
'AC_PROG_NM' => 1,
'AM_DEP_TRACK' => 1,
'_LT_AC_LANG_F77_CONFIG' => 1,
'AC_LTDL_ENABLE_INSTALL' => 1,
'_AM_CONFIG_MACRO_DIRS' => 1,
'AC_ENABLE_STATIC' => 1,
'PKG_CHECK_MODULES' => 1,
'LT_LIB_DLLOAD' => 1,
'_AM_OUTPUT_DEPENDENCY_COMMANDS' => 1,
'PKG_CHECK_EXISTS' => 1,
'VARNISH_PKG_GET_VAR' => 1,
'_AM_PROG_TAR' => 1,
'AC_LIBTOOL_CONFIG' => 1,
'VARNISH_VMOD_DIR' => 1,
'AC_LIBTOOL_COMPILER_OPTION' => 1,
'_LT_DLL_DEF_P' => 1,
'PKG_CHECK_VAR' => 1,
'AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH' => 1,
'_LT_AC_LANG_RC_CONFIG' => 1,
'_LT_LIBOBJ' => 1,
'LT_PATH_NM' => 1,
'AM_MAKE_INCLUDE' => 1,
'_LT_PROG_FC' => 1,
'AM_ENABLE_STATIC' => 1,
'AM_SILENT_RULES' => 1,
'_LTDL_SETUP' => 1,
'AC_LTDL_DLSYM_USCORE' => 1,
'AC_DISABLE_STATIC' => 1,
'_AM_SET_OPTIONS' => 1,
'm4_include' => 1,
'_AM_IF_OPTION' => 1,
'_LT_PROG_LTMAIN' => 1,
'AC_PATH_TOOL_PREFIX' => 1,
'AC_ENABLE_SHARED' => 1,
'_AM_AUTOCONF_VERSION' => 1,
'AM_PROG_LD' => 1,
'_LT_AC_SYS_COMPILER' => 1,
'PKG_INSTALLDIR' => 1,
'AC_LIBTOOL_SYS_MAX_CMD_LEN' => 1,
'AC_LIBTOOL_SYS_OLD_ARCHIVE' => 1,
'_LT_AC_LOCK' => 1,
'AC_LIBTOOL_LANG_CXX_CONFIG' => 1,
'_LT_PROG_ECHO_BACKSLASH' => 1,
'_LT_AC_FILE_LTDLL_C' => 1,
'AC_LIBTOOL_SYS_LIB_STRIP' => 1,
'LTVERSION_VERSION' => 1,
'AC_LTDL_SYMBOL_USCORE' => 1,
'_LT_PROG_F77' => 1,
'AC_LIBTOOL_POSTDEP_PREDEP' => 1,
'AC_DISABLE_FAST_INSTALL' => 1,
'PKG_CHECK_MODULES_STATIC' => 1,
'AC_LTDL_OBJDIR' => 1,
'AM_SET_CURRENT_AUTOMAKE_VERSION' => 1,
'PKG_NOARCH_INSTALLDIR' => 1,
'm4_pattern_allow' => 1,
'LT_AC_PROG_GCJ' => 1,
'AM_DISABLE_STATIC' => 1,
'AM_MISSING_HAS_RUN' => 1,
'AC_LIBTOOL_FC' => 1,
'_LT_AC_LANG_C_CONFIG' => 1,
'AM_MISSING_PROG' => 1,
'_LT_REQUIRED_DARWIN_CHECKS' => 1,
'_LT_AC_LANG_F77' => 1,
'LT_PATH_LD' => 1,
'_PKG_SHORT_ERRORS_SUPPORTED' => 1,
'AC_LIBTOOL_LANG_C_CONFIG' => 1,
'AC_LIBTOOL_PROG_LD_SHLIBS' => 1,
'AC_LIBTOOL_PROG_CC_C_O' => 1,
'AM_SET_LEADING_DOT' => 1,
'LT_SYS_DLSEARCH_PATH' => 1,
'LTOPTIONS_VERSION' => 1,
'VARNISH_VMODTOOL' => 1,
'AC_WITH_LTDL' => 1,
'AC_LIBTOOL_LINKER_OPTION' => 1,
'LT_SYS_DLOPEN_DEPLIBS' => 1,
'AM_RUN_LOG' => 1,
'_LT_AC_PROG_ECHO_BACKSLASH' => 1,
'LT_PROG_RC' => 1,
'AC_LTDL_SHLIBEXT' => 1,
'_LT_AC_LANG_CXX' => 1,
'_LT_PROG_CXX' => 1,
'AC_CONFIG_MACRO_DIR_TRACE' => 1,
'AC_LIBTOOL_SYS_DYNAMIC_LINKER' => 1,
'_LT_LINKER_OPTION' => 1,
'AC_LTDL_DLLIB' => 1,
'AM_PROG_CC_C_O' => 1,
'AC_LTDL_SYS_DLOPEN_DEPLIBS' => 1,
'_LT_PATH_TOOL_PREFIX' => 1,
'_LT_AC_PROG_CXXCPP' => 1,
'AM_DISABLE_SHARED' => 1,
'LT_SUPPORTED_TAG' => 1,
'AC_LIBTOOL_WIN32_DLL' => 1,
'LT_SYS_MODULE_EXT' => 1,
'LT_SYS_MODULE_PATH' => 1,
'_LT_AC_SHELL_INIT' => 1,
'AC_ENABLE_FAST_INSTALL' => 1,
'LT_AC_PROG_RC' => 1,
'AM_CONDITIONAL' => 1,
'AC_LTDL_SHLIBPATH' => 1,
'AC_CHECK_LIBM' => 1,
'AM_SET_DEPDIR' => 1,
'AC_LIBTOOL_LANG_RC_CONFIG' => 1,
'LT_AC_PROG_SED' => 1,
'LT_FUNC_DLSYM_USCORE' => 1,
'LT_LANG' => 1,
'AC_LIBTOOL_GCJ' => 1,
'AC_LIBTOOL_OBJDIR' => 1,
'VARNISH_VMOD_INCLUDES' => 1,
'AM_SANITY_CHECK' => 1,
'LT_OUTPUT' => 1,
'LT_INIT' => 1,
'LTDL_INIT' => 1,
'AC_LIBTOOL_PROG_COMPILER_PIC' => 1,
'_LT_PREPARE_SED_QUOTE_VARS' => 1,
'_LT_AC_TAGVAR' => 1,
'AM_AUX_DIR_EXPAND' => 1,
'_LT_AC_TAGCONFIG' => 1,
'_LT_AC_TRY_DLOPEN_SELF' => 1,
'AC_LIBTOOL_DLOPEN_SELF' => 1,
'AC_LIBTOOL_DLOPEN' => 1,
'include' => 1,
'_LT_WITH_SYSROOT' => 1,
'AC_LTDL_PREOPEN' => 1,
'AM_PROG_INSTALL_SH' => 1,
'AM_AUTOMAKE_VERSION' => 1,
'LT_CONFIG_LTDL_DIR' => 1,
'_AM_SUBST_NOTMAKE' => 1,
'AC_LIBTOOL_PROG_COMPILER_NO_RTTI' => 1,
'AC_PROG_LD_GNU' => 1,
'_LT_LINKER_BOILERPLATE' => 1,
'AC_LIBTOOL_PICMODE' => 1,
'AC_LIBTOOL_F77' => 1,
'LT_WITH_LTDL' => 1,
'm4_pattern_forbid' => 1,
'_AM_MANGLE_OPTION' => 1,
'LTOBSOLETE_VERSION' => 1,
'_LT_AC_CHECK_DLFCN' => 1,
'PKG_PROG_PKG_CONFIG' => 1,
'AC_LIBTOOL_SYS_HARD_LINK_LOCKS' => 1,
'AC_DEPLIBS_CHECK_METHOD' => 1,
'_AC_AM_CONFIG_HEADER_HOOK' => 1,
'fp_C_PROTOTYPES' => 1,
'AC_LIBLTDL_INSTALLABLE' => 1,
'_m4_warn' => 1,
'AM_PROG_NM' => 1,
'_LT_AC_LANG_GCJ' => 1,
'AC_CONFIG_MACRO_DIR' => 1,
'AC_PROG_EGREP' => 1,
'AM_PROG_INSTALL_STRIP' => 1,
'LTSUGAR_VERSION' => 1,
'AM_SUBST_NOTMAKE' => 1,
'LT_PROG_GCJ' => 1,
'LT_SYS_SYMBOL_USCORE' => 1,
'AC_DISABLE_SHARED' => 1,
'AM_C_PROTOTYPES' => 1,
'AM_CONFIG_HEADER' => 1,
'_AM_SET_OPTION' => 1,
'LT_LIB_M' => 1,
'_LT_COMPILER_OPTION' => 1,
'AC_PROG_LIBTOOL' => 1,
'AC_PROG_LD' => 1,
'AC_DEFUN' => 1,
'AC_LTDL_SYSSEARCHPATH' => 1,
'AC_PATH_MAGIC' => 1,
'AC_LIBTOOL_RC' => 1,
'LT_SYS_DLOPEN_SELF' => 1,
'AC_LIBTOOL_LANG_F77_CONFIG' => 1,
'_LT_AC_LANG_CXX_CONFIG' => 1,
'_LT_AC_SYS_LIBPATH_AIX' => 1,
'AC_LIBLTDL_CONVENIENCE' => 1,
'AM_OUTPUT_DEPENDENCY_COMMANDS' => 1,
'_LT_AC_LANG_GCJ_CONFIG' => 1,
'AC_PROG_LD_RELOAD_FLAG' => 1
}
], 'Autom4te::Request' ),
bless( [
'1',
1,
[
'/usr/share/autoconf'
],
[
'/usr/share/autoconf/autoconf/autoconf.m4f',
'aclocal.m4',
'configure.ac'
],
{
'LT_SUPPORTED_TAG' => 1,
'AC_FC_PP_DEFINE' => 1,
'AC_SUBST' => 1,
'_m4_warn' => 1,
'AC_REQUIRE_AUX_FILE' => 1,
'AM_PROG_MOC' => 1,
'AM_POT_TOOLS' => 1,
'm4_pattern_forbid' => 1,
'AM_INIT_AUTOMAKE' => 1,
'AM_PROG_CC_C_O' => 1,
'AC_CONFIG_AUX_DIR' => 1,
'AC_CANONICAL_BUILD' => 1,
'AM_PROG_MKDIR_P' => 1,
'm4_include' => 1,
'sinclude' => 1,
'AM_PATH_GUILE' => 1,
'AM_PROG_LIBTOOL' => 1,
'AM_GNU_GETTEXT_INTL_SUBDIR' => 1,
'AC_FC_SRCEXT' => 1,
'AC_FC_PP_SRCEXT' => 1,
'LT_CONFIG_LTDL_DIR' => 1,
'AM_SILENT_RULES' => 1,
'_AM_SUBST_NOTMAKE' => 1,
'AM_XGETTEXT_OPTION' => 1,
'AM_PROG_AR' => 1,
'_AM_COND_IF' => 1,
'm4_sinclude' => 1,
'AM_AUTOMAKE_VERSION' => 1,
'_AM_COND_ENDIF' => 1,
'AC_CONFIG_LIBOBJ_DIR' => 1,
'AC_CONFIG_SUBDIRS' => 1,
'AC_CONFIG_HEADERS' => 1,
'include' => 1,
'AM_GNU_GETTEXT' => 1,
'AM_ENABLE_MULTILIB' => 1,
'AC_DEFINE_TRACE_LITERAL' => 1,
'AM_NLS' => 1,
'AM_MAKEFILE_INCLUDE' => 1,
'LT_INIT' => 1,
'AH_OUTPUT' => 1,
'AM_PROG_FC_C_O' => 1,
'AC_PROG_LIBTOOL' => 1,
'_LT_AC_TAGCONFIG' => 1,
'AC_INIT' => 1,
'AM_PROG_CXX_C_O' => 1,
'AC_CONFIG_LINKS' => 1,
'AC_CANONICAL_HOST' => 1,
'_AM_COND_ELSE' => 1,
'AC_LIBSOURCE' => 1,
'AM_EXTRA_RECURSIVE_TARGETS' => 1,
'AM_MAINTAINER_MODE' => 1,
'AM_PROG_F77_C_O' => 1,
'_AM_MAKEFILE_INCLUDE' => 1,
'AC_SUBST_TRACE' => 1,
'AC_CONFIG_FILES' => 1,
'AC_CANONICAL_TARGET' => 1,
'm4_pattern_allow' => 1,
'AM_CONDITIONAL' => 1,
'AC_CANONICAL_SYSTEM' => 1,
'AC_FC_FREEFORM' => 1
}
], 'Autom4te::Request' )
);
This diff is collapsed.
This diff is collapsed.
/*-
* Copyright (c) 2007-2011 Varnish Software AS
* All rights reserved.
*
* Author: Cecilie Fritzvold <cecilihf@linpro.no>
* Author: Tollef Fog Heen <tfheen@varnish-software.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*
* Nagios plugin for Varnish
*/
#include <inttypes.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/time.h>
#include <locale.h>
#include <assert.h>
#if defined(HAVE_VARNISHAPI_4) || defined(HAVE_VARNISHAPI_4_1)
#include <vapi/vsc.h>
#include <vapi/vsm.h>
#elif defined(HAVE_VARNISHAPI_3)
#include "vsc.h"
#include "varnishapi.h"
#endif
static int verbose = 0;
struct range {
intmax_t lo;
intmax_t hi;
int inverted:1;
int defined:1;
};
static struct range critical;
static struct range warning;
enum {
NAGIOS_OK = 0,
NAGIOS_WARNING = 1,
NAGIOS_CRITICAL = 2,
NAGIOS_UNKNOWN = 3,
};
static const char *status_text[] = {
[NAGIOS_OK] = "OK",
[NAGIOS_WARNING] = "WARNING",
[NAGIOS_CRITICAL] = "CRITICAL",
[NAGIOS_UNKNOWN] = "UNKNOWN",
};
/*
* Parse a range specification
*/
static int
parse_range(const char *spec, struct range *range)
{
const char *delim;
char *end;
/* @ means invert the range */
if (*spec == '@') {
++spec;
range->inverted = 1;
} else {
range->inverted = 0;
}
/* empty spec... */
if (*spec == '\0')
return (-1);
if ((delim = strchr(spec, ':')) != NULL) {
/*
* The Nagios plugin documentation says nothing about how
* to interpret ":N", so we disallow it. Allowed forms
* are "~:N", "~:", "M:" and "M:N".
*/
if (delim - spec == 1 && *spec == '~') {
range->lo = INTMAX_MIN;
} else {
range->lo = strtoimax(spec, &end, 10);
if (end != delim)
return (-1);
}
if (*(delim + 1) != '\0') {
range->hi = strtoimax(delim + 1, &end, 10);
if (*end != '\0')
return (-1);
} else {
range->hi = INTMAX_MAX;
}
} else {
/*
* Allowed forms are N
*/
range->lo = 0;
range->hi = strtol(spec, &end, 10);
if (*end != '\0')
return (-1);
}
/*
* Sanity
*/
if (range->lo > range->hi)
return (-1);
range->defined = 1;
return (0);
}
/*
* Check if a given value is within a given range.
*/
static int
inside_range(intmax_t value, const struct range *range)
{
if (range->inverted)
return (value < range->lo || value > range->hi);
return (value >= range->lo && value <= range->hi);
}
/*
* Check if the thresholds against the value and return the appropriate
* status code.
*/
static int
check_thresholds(intmax_t value)
{
if (!warning.defined && !critical.defined)
return (NAGIOS_UNKNOWN);
if (critical.defined && !inside_range(value, &critical))
return (NAGIOS_CRITICAL);
if (warning.defined && !inside_range(value, &warning))
return (NAGIOS_WARNING);
return (NAGIOS_OK);
}
struct stat_priv {
char *param;
const char *info;
intmax_t value;
int found;
intmax_t cache_hit;
intmax_t cache_miss;
};
static int
check_stats_cb(void *priv, const struct VSC_point * const pt)
{
struct stat_priv *p;
char tmp[1024];
if (pt == NULL)
return(0);
#if defined(HAVE_VARNISHAPI_4_1) || defined(HAVE_VARNISHAPI_4)
assert(sizeof(tmp) > (strlen(pt->section->fantom->type) + 1 +
strlen(pt->section->fantom->ident) + 1 +
strlen(pt->desc->name) + 1));
snprintf(tmp, sizeof(tmp), "%s%s%s%s%s",
(pt->section->fantom->type[0] == 0 ? "" : pt->section->fantom->type),
(pt->section->fantom->type[0] == 0 ? "" : "."),
(pt->section->fantom->ident[0] == 0 ? "" : pt->section->fantom->ident),
(pt->section->fantom->ident[0] == 0 ? "" : "."),
pt->desc->name);
p = priv;
#endif
#if defined(HAVE_VARNISHAPI_4_1)
assert(!strcmp(pt->desc->ctype, "uint64_t"));
#elif defined(HAVE_VARNISHAPI_4)
assert(!strcmp(pt->desc->fmt, "uint64_t"));
#elif defined(HAVE_VARNISHAPI_3)
assert(sizeof(tmp) > (strlen(pt->class) + 1 +
strlen(pt->ident) + 1 +
strlen(pt->name) + 1));
snprintf(tmp, sizeof(tmp), "%s%s%s%s%s",
(pt->class[0] == 0 ? "" : pt->class),
(pt->class[0] == 0 ? "" : "."),
(pt->ident[0] == 0 ? "" : pt->ident),
(pt->ident[0] == 0 ? "" : "."),
pt->name);
p = priv;
assert(!strcmp(pt->fmt, "uint64_t"));
#endif
if (strcmp(tmp, p->param) == 0) {
p->found = 1;
#if defined(HAVE_VARNISHAPI_4) || defined(HAVE_VARNISHAPI_4_1)
p->info = pt->desc->sdesc;
#elif defined(HAVE_VARNISHAPI_3)
p->info = pt->desc;
#endif
p->value = *(const volatile uint64_t*)pt->ptr;
} else if (strcmp(p->param, "ratio") == 0) {
if (strcmp(tmp, "cache_hit") == 0 || strcmp(tmp, "MAIN.cache_hit") == 0) {
p->found = 1;
p->cache_hit = *(const volatile uint64_t*)pt->ptr;
} else if (strcmp(tmp, "cache_miss") == 0 || strcmp(tmp, "MAIN.cache_miss") == 0) {
p->cache_miss = *(const volatile uint64_t*)pt->ptr;
}
}
return (0);
}
/*
* Check the statistics for the requested parameter.
*/
static void
check_stats(struct VSM_data *vd, char *param)
{
int status;
struct stat_priv priv;
priv.found = 0;
priv.param = param;
#if defined(HAVE_VARNISHAPI_4) || defined(HAVE_VARNISHAPI_4_1)
(void)VSC_Iter(vd, NULL, check_stats_cb, &priv);
#elif defined(HAVE_VARNISHAPI_3)
(void)VSC_Iter(vd, check_stats_cb, &priv);
#endif
if (strcmp(param, "ratio") == 0) {
intmax_t total = priv.cache_hit + priv.cache_miss;
priv.value = total ? (100 * priv.cache_hit / total) : 0;
priv.info = "Cache hit ratio";
}
if (priv.found != 1) {
printf("Unknown parameter '%s'\n", param);
exit(1);
}
status = check_thresholds(priv.value);
printf("VARNISH %s: %s (%'jd)|%s=%jd\n", status_text[status],
priv.info, priv.value, param, priv.value);
exit(status);
}
/*-------------------------------------------------------------------------------*/
static void
help(void)
{
fprintf(stderr, "usage: "
"check_varnish [-lv] [-n varnish_name] [-p param_name [-c N] [-w N]]\n"
"\n"
"-v Increase verbosity.\n"
"-n varnish_name Specify the Varnish instance name\n"
"-p param_name Specify the parameter to check (see below).\n"
" The default is 'ratio'.\n"
"-c [@][lo:]hi Set critical threshold\n"
"-w [@][lo:]hi Set warning threshold\n"
"\n"
"All items reported by varnishstat(1) are available - use the\n"
"identifier listed in the left column by 'varnishstat -l'.\n"
"\n"
"Examples for Varnish 3.x:\n"
"\n"
"uptime How long the cache has been running (in seconds)\n"
"ratio The cache hit ratio expressed as a percentage of hits to\n"
" hits + misses. Default thresholds are 95 and 90.\n"
"usage Cache file usage as a percentage of the total cache space.\n"
"\n"
"Examples for Varnish 4.x:\n"
"\n"
"ratio The cache hit ratio expressed as a percentage of hits to\n"
" hits + misses. Default thresholds are 95 and 90.\n"
"MAIN.uptime How long the cache has been running (in seconds).\n"
"MAIN.n_purges Number of purge operations executed.\n"
);
exit(0);
}
static void
usage(void)
{
fprintf(stderr, "usage: "
"check_varnish [-lv] [-n varnish_name] [-p param_name [-c N] [-w N]]\n");
exit(3);
}
int
main(int argc, char **argv)
{
struct VSM_data *vd;
char *param = NULL;
int opt;
setlocale(LC_ALL, "");
vd = VSM_New();
#if defined(HAVE_VARNISHAPI_3)
VSC_Setup(vd);
#endif
while ((opt = getopt(argc, argv, VSC_ARGS "c:hn:p:vw:")) != -1) {
switch (opt) {
case 'c':
if (parse_range(optarg, &critical) != 0)
usage();
break;
case 'h':
help();
break;
case 'n':
VSC_Arg(vd, opt, optarg);
break;
case 'p':
param = strdup(optarg);
break;
case 'v':
++verbose;
break;
case 'w':
if (parse_range(optarg, &warning) != 0)
usage();
break;
default:
if (VSC_Arg(vd, opt, optarg) > 0)
break;
usage();
}
}
#if defined(HAVE_VARNISHAPI_4) || defined(HAVE_VARNISHAPI_4_1)
if (VSM_Open(vd))
exit(1);
#elif defined(HAVE_VARNISHAPI_3)
if (VSC_Open(vd, 1))
exit(1);
#endif
/* Default: if no param specified, check hit ratio. If no warning
* and critical values are specified either, set these to default.
*/
if (param == NULL) {
param = strdup("ratio");
if (!warning.defined)
parse_range("95:", &warning);
if (!critical.defined)
parse_range("90:", &critical);
}
if (!param)
usage();
check_stats(vd, param);
exit(0);
}
This diff is collapsed.
This diff is collapsed.