Patch for Nagios Varnish plugin - add multiinstances

wolvverine wolvverinepld at gmail.com
Fri Jul 25 17:34:28 CEST 2014


- add option for instance name

--- check_varnish.pl.orig 2014-07-22 11:12:36.141550908 +0200
+++ check_varnish.pl 2014-07-22 11:15:45.898193885 +0200
@@ -28,11 +28,14 @@

 # Parse command line options
 my @specs;
+my $instancename = $ENV{HOSTNAME};
 my ( $list, $help );
+
 GetOptions(
     "spec|s=s" => \@specs,
     "list|l"   => \$list,
-    "help|h"   => \$help
+    "help|h"   => \$help,
+    "instancename|n=s"  => \$instancename
 );

 # Print help if they asked for it
@@ -41,7 +44,7 @@
 }

 if ($list) {
-    print_list();
+    print_list($instancename);
 }

 # Global vars that hold the parsed varnishstat output
@@ -57,7 +60,7 @@
     print_help();
 }

-parse_varnishstat();
+parse_varnishstat($instancename);

 foreach (@specs) {

@@ -154,8 +157,9 @@

 # Turn the varnishstat output into a Perl hash
 sub parse_varnishstat {
+    my ($instancename) = @_;

-    open (VARNISHSTAT, "/usr/bin/varnishstat -1 |");
+    open (VARNISHSTAT, "/usr/bin/varnishstat -1 -n" . $instancename .  " |");

     while (<VARNISHSTAT>) {
         s/\s+/ /g;    # normalise spaces
@@ -216,8 +220,8 @@

 Usage:

- check_varnish.pl --spec=[spec definition] --spec=[spec definition]
- check_varnish.pl --list
+ check_varnish.pl [--instancename=instance ] --spec=[spec definition]
--spec=[spec definition]
+ check_varnish.pl --list [--instancename=instance ]
  check_varnish.pl --help

 Options:
@@ -254,6 +258,9 @@
     --help
         Displays this message.

+    --instancename
+ name of varnish instance
+
 check_varnish.pl comes with absolutely NO WARRANTY either implied or explicit
 This program is licensed under the terms of the
 GNU General Public License (check source code for details)
@@ -265,10 +272,11 @@
 }

 sub print_list {
+    my ($instancename) = @_;

     # Print a list of all the varnishstat counters
     # and their (sometimes meaningless!) description
-    parse_varnishstat();
+    parse_varnishstat($instancename);

     if ($list) {
         print "\nAvailable Varnish performance counters:\n\n";



More information about the varnish-dev mailing list