git.lirion.de

Of git, get, and gud

summaryrefslogtreecommitdiffstats
path: root/nagios-plugins-contrib-24.20190301~bpo9+1/debian/patches/check_varnish
diff options
context:
space:
mode:
authormail_redacted_for_web 2019-04-17 19:07:19 +0200
committermail_redacted_for_web 2019-04-17 19:07:19 +0200
commit1e2387474a449452b78520b9ad96a8b4b5e99722 (patch)
tree836889471eec7d2aac177405068e2a8f1e2b1978 /nagios-plugins-contrib-24.20190301~bpo9+1/debian/patches/check_varnish
downloadnagios-plugins-contrib-1e2387474a449452b78520b9ad96a8b4b5e99722.tar.bz2
initial commit of source fetch
Diffstat (limited to 'nagios-plugins-contrib-24.20190301~bpo9+1/debian/patches/check_varnish')
-rw-r--r--nagios-plugins-contrib-24.20190301~bpo9+1/debian/patches/check_varnish/fix_for_v56186
1 files changed, 186 insertions, 0 deletions
diff --git a/nagios-plugins-contrib-24.20190301~bpo9+1/debian/patches/check_varnish/fix_for_v56 b/nagios-plugins-contrib-24.20190301~bpo9+1/debian/patches/check_varnish/fix_for_v56
new file mode 100644
index 0000000..91c93fb
--- /dev/null
+++ b/nagios-plugins-contrib-24.20190301~bpo9+1/debian/patches/check_varnish/fix_for_v56
@@ -0,0 +1,186 @@
+From d53252d965aaa1889a8b56a681c464c6ca04f632 Mon Sep 17 00:00:00 2001
+From: Jean-Louis Dupond <jean-louis@dupond.be>
+Date: Sat, 23 Dec 2017 13:06:01 +0100
+Subject: [PATCH] Switch to new functions for Varnish 5.2
+
+---
+ check_varnish.c | 54 +++++++++++++++++++++++++++++++++++++++++--------
+ configure.ac | 18 ++++++++++-------
+ 2 files changed, 57 insertions(+), 15 deletions(-)
+
+diff --git a/check_varnish/src/check_varnish.c b/check_varnish/src/check_varnish.c
+index 809657c..83aacdc 100644
+--- a/check_varnish/src/check_varnish.c
++++ b/check_varnish/src/check_varnish.c
+@@ -43,7 +43,7 @@
+ #include <locale.h>
+ #include <assert.h>
+
+-#if defined(HAVE_VARNISHAPI_4) || defined(HAVE_VARNISHAPI_4_1)
++#if defined(HAVE_VARNISHAPI_4) || defined(HAVE_VARNISHAPI_4_1) || defined(HAVE_VARNISHAPI_5)
+ #include <vapi/vsc.h>
+ #include <vapi/vsm.h>
+ #elif defined(HAVE_VARNISHAPI_3)
+@@ -185,7 +185,11 @@ check_stats_cb(void *priv, const struct VSC_point * const pt)
+ if (pt == NULL)
+ return(0);
+
+-#if defined(HAVE_VARNISHAPI_4_1) || defined(HAVE_VARNISHAPI_4)
++#if defined(HAVE_VARNISHAPI_5)
++ assert(sizeof(tmp) > (strlen(pt->name) + 1));
++ snprintf(tmp, sizeof(tmp), "%s", pt->name);
++ p = priv;
++#elif 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));
+@@ -197,7 +201,9 @@ check_stats_cb(void *priv, const struct VSC_point * const pt)
+ pt->desc->name);
+ p = priv;
+ #endif
+-#if defined(HAVE_VARNISHAPI_4_1)
++#if defined(HAVE_VARNISHAPI_5)
++ assert(!strcmp(pt->ctype, "uint64_t"));
++#elif defined(HAVE_VARNISHAPI_4_1)
+ assert(!strcmp(pt->desc->ctype, "uint64_t"));
+ #elif defined(HAVE_VARNISHAPI_4)
+ assert(!strcmp(pt->desc->fmt, "uint64_t"));
+@@ -216,7 +222,9 @@ check_stats_cb(void *priv, const struct VSC_point * const pt)
+ #endif
+ if (strcmp(tmp, p->param) == 0) {
+ p->found = 1;
+-#if defined(HAVE_VARNISHAPI_4) || defined(HAVE_VARNISHAPI_4_1)
++#if defined(HAVE_VARNISHAPI_5)
++ p->info = pt->sdesc;
++#elif defined(HAVE_VARNISHAPI_4) || defined(HAVE_VARNISHAPI_4_1)
+ p->info = pt->desc->sdesc;
+ #elif defined(HAVE_VARNISHAPI_3)
+ p->info = pt->desc;
+@@ -237,7 +245,11 @@ check_stats_cb(void *priv, const struct VSC_point * const pt)
+ * Check the statistics for the requested parameter.
+ */
+ static void
++#if defined(HAVE_VARNISHAPI_5)
++check_stats(struct vsc *vsc, struct vsm *vsm, char *param)
++#else
+ check_stats(struct VSM_data *vd, char *param)
++#endif
+ {
+ int status;
+ struct stat_priv priv;
+@@ -245,7 +257,9 @@ check_stats(struct VSM_data *vd, char *param)
+ priv.found = 0;
+ priv.param = param;
+
+-#if defined(HAVE_VARNISHAPI_4) || defined(HAVE_VARNISHAPI_4_1)
++#if defined(HAVE_VARNISHAPI_5)
++ (void)VSC_Iter(vsc, vsm, check_stats_cb, &priv);
++#elif 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);
+@@ -315,18 +329,25 @@ usage(void)
+ int
+ main(int argc, char **argv)
+ {
++#if defined(HAVE_VARNISHAPI_5)
++ struct vsm *vd;
++ struct vsc *vsc;
++#else
+ struct VSM_data *vd;
++#endif
+ char *param = NULL;
+ int opt;
+
+ setlocale(LC_ALL, "");
+
+ vd = VSM_New();
+-#if defined(HAVE_VARNISHAPI_3)
++#if defined(HAVE_VARNISHAPI_5)
++ vsc = VSC_New();
++#elif defined(HAVE_VARNISHAPI_3)
+ VSC_Setup(vd);
+ #endif
+
+- while ((opt = getopt(argc, argv, VSC_ARGS "c:hn:p:vw:")) != -1) {
++ while ((opt = getopt(argc, argv, "c:hn:p:vw:")) != -1) {
+ switch (opt) {
+ case 'c':
+ if (parse_range(optarg, &critical) != 0)
+@@ -336,7 +357,11 @@ main(int argc, char **argv)
+ help();
+ break;
+ case 'n':
++#if defined(HAVE_VARNISHAPI_5)
++ VSC_Arg(vsc, opt, optarg);
++#else
+ VSC_Arg(vd, opt, optarg);
++#endif
+ break;
+ case 'p':
+ param = strdup(optarg);
+@@ -349,13 +374,22 @@ main(int argc, char **argv)
+ usage();
+ break;
+ default:
++#if defined(HAVE_VARNISHAPI_5)
++ if (VSC_Arg(vsc, opt, optarg) > 0)
++#else
+ if (VSC_Arg(vd, opt, optarg) > 0)
++#endif
+ break;
+ usage();
+ }
+ }
+
+-#if defined(HAVE_VARNISHAPI_4) || defined(HAVE_VARNISHAPI_4_1)
++#if defined(HAVE_VARNISHAPI_5)
++ if (VSM_Attach(vd, -1) < 0) {
++ printf("varnish plugin: Cannot attach to varnish. %s", VSM_Error(vd));
++ exit(1);
++ }
++#elif defined(HAVE_VARNISHAPI_4) || defined(HAVE_VARNISHAPI_4_1)
+ if (VSM_Open(vd))
+ exit(1);
+ #elif defined(HAVE_VARNISHAPI_3)
+@@ -377,7 +411,11 @@ main(int argc, char **argv)
+ if (!param)
+ usage();
+
++#if defined(HAVE_VARNISHAPI_5)
++ check_stats(vsc, vd, param);
++#else
+ check_stats(vd, param);
++#endif
+
+ exit(0);
+ }
+diff --git a/check_varnish/src/configure.ac b/check_varnish/src/configure.ac
+index c7946c2..8b0b2ec 100644
+--- a/check_varnish/src/configure.ac
++++ b/check_varnish/src/configure.ac
+@@ -21,13 +21,17 @@ AC_PROG_LIBTOOL
+ AC_PROG_MAKE_SET
+
+ # Checks for libraries.
+-PKG_CHECK_MODULES([VARNISHAPI], [varnishapi >= 4.1],
+- [AC_DEFINE([HAVE_VARNISHAPI_4_1], [1], [Use VARNISHAPI v4.1])],
+- [PKG_CHECK_MODULES([VARNISHAPI], [varnishapi >= 4],
+- [AC_DEFINE([HAVE_VARNISHAPI_4], [1], [Use VARNISHAPI v4])],
+- [PKG_CHECK_MODULES([VARNISHAPI], [varnishapi >= 3],
+- [AC_DEFINE([HAVE_VARNISHAPI_3], [1], [Use VARNISHAPI v3])],
+- [AC_MSG_ERROR([Could not find neither varnishapi v4 nor v3.])])
++PKG_CHECK_MODULES([VARNISHAPI], [varnishapi >= 5.2],
++ [AC_DEFINE([HAVE_VARNISHAPI_5], [1], [Use VARNISHAPI v5])],
++ [PKG_CHECK_MODULES([VARNISHAPI], [varnishapi >= 4.1],
++ [AC_DEFINE([HAVE_VARNISHAPI_4_1], [1], [Use VARNISHAPI v4.1])],
++ [PKG_CHECK_MODULES([VARNISHAPI], [varnishapi >= 4],
++ [AC_DEFINE([HAVE_VARNISHAPI_4], [1], [Use VARNISHAPI v4])],
++ [PKG_CHECK_MODULES([VARNISHAPI], [varnishapi >= 3],
++ [AC_DEFINE([HAVE_VARNISHAPI_3], [1], [Use VARNISHAPI v3])],
++ [AC_MSG_ERROR([Could not find neither varnishapi v4 nor v3.])])
++ ]
++ )
+ ]
+ )
+ ]
"w"> 2>&1 # ######################################################################## # Set up constants, etc. # ######################################################################## STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 STATE_DEPENDENT=4 # ######################################################################## # Run the program. # ######################################################################## main() { # Get options for o; do case "${o}" in -c) shift; OPT_CRIT="${1}"; shift; ;; --defaults-file) shift; OPT_DEFT="${1}"; shift; ;; -H) shift; OPT_HOST="${1}"; shift; ;; -l) shift; OPT_USER="${1}"; shift; ;; -L) shift; OPT_LOPA="${1}"; shift; ;; -p) shift; OPT_PASS="${1}"; shift; ;; -P) shift; OPT_PORT="${1}"; shift; ;; -S) shift; OPT_SOCK="${1}"; shift; ;; -t) shift; OPT_TMPDIR="${1}"; shift; ;; -w) shift; OPT_WARN="${1}"; shift; ;; --version) grep -A2 '^=head1 VERSION' "$0" | tail -n1; exit 0 ;; --help) perl -00 -ne 'm/^ Usage:/ && print' "$0"; exit 0 ;; -*) echo "Unknown option ${o}. Try --help."; exit 1; ;; esac done if [ -e '/etc/nagios/mysql.cnf' ]; then OPT_DEFT="${OPT_DEFT:-/etc/nagios/mysql.cnf}" fi if is_not_sourced; then if [ -n "$1" ]; then echo "WARN spurious command-line options: $@" exit 1 fi fi # If any connection option was given, then try to log in to find the server's # tmpdir. if [ "${OPT_DEFT}${OPT_HOST}${OPT_USER}${OPT_PASS}${OPT_PORT}${OPT_SOCK}" ]; then OPT_TMPDIR=$(mysql_exec "SELECT @@tmpdir") || exit $? elif [ -z "${OPT_TMPDIR}" ]; then OPT_TMPDIR="${TMPDIR:-/tmp/}" fi # TODO: We could auto-check every running instance, not just one. local NOTE="OK no deleted files" local PROC_ID=$(_pidof mysqld | head -n1) if [ "${PROC_ID}" ]; then local TEMP=$(mktemp -t "${0##*/}.XXXXXX") || exit $? trap "rm -f '${TEMP}' >/dev/null 2>&1" EXIT if _lsof "${PROC_ID}" > "${TEMP}" ; then # If lsof exists, but you run it as non-root, you'll get a file with a # bunch of this stuff: # mysqld 15287 ... /proc/15287/cwd (readlink: Permission denied) # We have to detect this and return UNK. if grep -v -e denied -e COMMAND "${TEMP}" >/dev/null 2>&1; then local FILES=$(check_deleted_files "${TEMP}" "${OPT_TMPDIR}") NOTE="open but deleted files: ${FILES}" if [ "${FILES}" -a -z "${OPT_WARN}" ]; then NOTE="CRIT $NOTE" elif [ "${FILES}" ]; then NOTE="WARN $NOTE" else NOTE="OK no deleted files" fi else NOTE="UNK You must execute lsof with root privileges" fi else NOTE="UNK could not list MySQL's open files" fi else NOTE="UNK could not find a mysqld process" fi echo $NOTE } # ######################################################################## # A wrapper around pidof, which might not exist. The first argument is the # command name to match. # ######################################################################## _pidof() { if ! pidof "${1}" 2>/dev/null; then ps axo pid,ucomm | awk -v comm="${1}" '$2 == comm { print $1 }' fi } # ######################################################################## # Execute a MySQL command. # ######################################################################## mysql_exec() { mysql ${OPT_DEFT:+--defaults-file="${OPT_DEFT}"} \ ${OPT_LOPA:+--login-path="${OPT_LOPA}"} \ ${OPT_HOST:+-h"${OPT_HOST}"} ${OPT_PORT:+-P"${OPT_PORT}"} \ ${OPT_USER:+-u"${OPT_USER}"} ${OPT_PASS:+-p"${OPT_PASS}"} \ ${OPT_SOCK:+-S"${OPT_SOCK}"} -ss -e "$1" } # ######################################################################## # A wrapper around lsof, which might not exist. The first argument is the # process ID to match. Otherwise, the fallback of listing /proc/pid/fd # will probably only work on Linux. For BSD, fstat will be used. # ######################################################################## _lsof() { PATH="$PATH:/usr/sbin:/sbin" if ! lsof -p $1 2>/dev/null; then if ! /bin/ls -l /proc/$1/fd 2>/dev/null; then fstat -p $1 2>/dev/null fi fi } # ######################################################################## # Generate a list of file handles that MySQL has open, but which are deleted, # and are not temp files such as /tmp/ib* files (InnoDB) or /tmp/ML* files # (binary logging). The first argument is a file containing the output of lsof # or ls -l for the open files. The second argument is the server's tmpdir. # ######################################################################## check_deleted_files() { awk -v tmpdir="${2}" ' /\(deleted\)/ { if ( index($0, tmpdir) == 0 ) { if ( $NF ~ /deleted/ ) { lf=NF-1; } else { lf=NF; } print $lf; }}' "${1}" } # ######################################################################## # Determine whether this program is being executed directly, or sourced/included # from another file. # ######################################################################## is_not_sourced() { [ "${0##*/}" = "pmp-check-mysql-deleted-files" ] || [ "${0##*/}" = "bash" -a "$_" = "$0" ] } # ######################################################################## # Execute the program if it was not included from another file. # This makes it possible to include without executing, and thus test. # ######################################################################## if is_not_sourced; then OUTPUT=$(main "$@") EXITSTATUS=$STATE_UNKNOWN case "${OUTPUT}" in UNK*) EXITSTATUS=$STATE_UNKNOWN; ;; OK*) EXITSTATUS=$STATE_OK; ;; WARN*) EXITSTATUS=$STATE_WARNING; ;; CRIT*) EXITSTATUS=$STATE_CRITICAL; ;; esac echo "${OUTPUT}" exit $EXITSTATUS fi # ############################################################################ # Documentation # ############################################################################ : <<'DOCUMENTATION' =pod =head1 NAME pmp-check-mysql-deleted-files - Alert when MySQL's files are deleted. =head1 SYNOPSIS Usage: pmp-check-mysql-deleted-files [OPTIONS] Options: -c CRIT Critical threshold; ignored. --defaults-file FILE Only read mysql options from the given file. Defaults to /etc/nagios/mysql.cnf if it exists. -H HOST MySQL hostname. -l USER MySQL username. -L LOGIN-PATH Use login-path to access MySQL (with MySQL client 5.6). -p PASS MySQL password. -P PORT MySQL port. -S SOCKET MySQL socket file. -w WARN Warning threshold; changes the alert to WARN instead of CRIT. --help Print help and exit. --version Print version and exit. Options must be given as --option value, not --option=value or -Ovalue. Use perldoc to read embedded documentation with more details. =head1 DESCRIPTION This Nagios plugin looks at the files that the mysqld process has open, and warns if any of them are deleted that shouldn't be. This typically happens when there is a poorly written logrotate script or when a human makes a mistake at the command line. This can cause several bad effects. If a table has been deleted, of course, it is a serious matter. Such a file can also potentially fill up the disk invisibly. If the file is the server's log, it might mean that logging is effectively broken and any problems the server experiences could be undiagnosable. The plugin accepts the -w and -c options for compatibility with standard Nagios plugin conventions, but they are not based on a threshold. Instead, the plugin raises a critical alert by default, and if the -w option is given, it raises a warning instead, regardless of the option's value. This plugin doesn't alert about deleted temporary files, which are not a problem. By default, this plugin assumes that the server's temporary directory is either the TMPDIR environment variable, or if that is not set, then /tmp/. If you specify MySQL authentication options, the value will log into the specified MySQL instance and look at the C<tmpdir> variable to find the temporary directory. This plugin looks at the first running instance of MySQL, as found in the system process table, so it will not work on systems that have multiple instances running. It probably works best on Linux, though it might work on other operating systems. It relies on either lsof or fstat or the ability to list the files in the process's /proc/pid/fd directory. =head1 PRIVILEGES This plugin executes the following commands against MySQL: =over =item * C<SELECT> the system variable C<@@tmpdir>. =back This plugin executes the following UNIX commands that may need special privileges: =over =item * ps =item * C<lsof> or C<ls /proc/$pid/fd> (Linux), C<fstat> (BSD) =back The plugin should be able to find mysqld PID using C<ps> command. On BSD, if C<sysctl> option C<security.bsd.see_other_uids> is set to 0, C<ps> will not return mysqld PID if the plugin run from non-root user. =head1 COPYRIGHT, LICENSE, AND WARRANTY This program is copyright 2012-$CURRENT_YEAR$ Baron Schwartz, 2012-$CURRENT_YEAR$ Percona Inc. Feedback and improvements are welcome. THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. =head1 VERSION $PROJECT_NAME$ pmp-check-mysql-deleted-files $VERSION$ =cut DOCUMENTATION