**Update: 2 July 2014. Updated to new version 1.1
I have written a check for nagios/icinga to check the varnish backend health. You can get the latest version from github . The version at the time of posting at the bottom of this message.
The defaults are RHEL defaults and ./check_varnishbackends.py should work without any options unless you want to override them. Here is the Nagios/Icinga Setup,
Register the service
1 2 3 4 5 6 |
define service { register 0 name check_varnishbackends service_description Varnish Backends use generic-service } |
Assign to host “server”
1 2 3 4 5 6 |
define service { service_description Varnish Backend host_name server use check_varnishbackends check_command remote_nrpe!check_varnishbackends -a "127.0.0.1" "6082" "/etc/varnish/secret" "/usr/bin/varnishadm" } |
Setup NRPE (Make sure user has permission to varnish secret file or use sudo)
1 |
command[check_varnishbackends]=/usr/local/nagios/libexec/check_varnishbackends.py --host $ARG1$ --port $ARG2$ --secret $ARG3$ --path $ARG4$ |
Version at time of posting,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
#!/usr/bin/env python # Nagios Varnish Backend Check # v1.1 # URL: www.admingeekz.com # Contact: sales@admingeekz.com # # # Copyright (c) 2013, AdminGeekZ Ltd # All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # import sys import optparse import subprocess def runcommand(command, exit_on_fail=True): try: process = subprocess.Popen(command.split(" "), stdout=subprocess.PIPE) output, unused_err = process.communicate() retcode = process.poll() return output except OSError, e: print "Error: Executing command failed, does it exist?" sys.exit(2) def main(argv): o = optparse.OptionParser(conflict_handler="resolve", description="Nagios plugin to check varnish backend health.") o.add_option('-H', '--host', action='store', type='string', dest='host', default='127.0.0.1', help='The ip varnishadm is listening on') o.add_option('-P', '--port', action='store', type='int', dest='port', default=6082, help='The port varnishadm is listening on') o.add_option('-s', '--secret', action='store', type='string', dest='secret', default='/etc/varnish/secret', help='The path to the secret file') o.add_option('-p', '--path', action='store', type='string', dest='path', default='/usr/bin/varnishadm', help='The path to the varnishadm binary') options=o.parse_args()[0] command = runcommand("%(path)s -S %(secret)s -T %(host)s:%(port)s debug.health" % options.__dict__) backends = command.split("\n") backends_healthy, backends_sick = [], [] for line in backends: if line.startswith("Backend") and line.find("test")==-1: if line.endswith("Healthy"): backends_healthy.append(line.split(" ")[1]) else: backends_sick.append(line.split(" ")[1]) if backends_sick: print "%s backends are down. %s" % (len(backends_sick), "".join(backends_sick)) sys.exit(2) if not backends_sick and not backends_healthy: print "No backends detected. If this is an error, see readme.txt" sys.exit(1) print "All %s backends are healthy" % (len(backends_healthy)) sys.exit(0) if __name__ == "__main__": main(sys.argv[1:]) |
Hi
This nagios check seems to be working fine with varnish 2.0 but it doesn’t work with Varnish 3.x
In fact varnish has made a lot of changes. This has resulted in backend check with no result (matching case netither healthy nor sick).
Requesting you to update script to accommodate for both varnish 2.x and 3.x
Thanks
Anup Nair, I just seen this. I will have alook and get this fixed today.
This seems to work fine but I did note during testing that if you don’t have the probe setup then it varnish doesn’t return any information on the backends. I have added some documentation to the file on how to set this up. Can you report back if it’s functioning fine once you add this?
Here’s the updated version: https://github.com/admingeekz/nagios-varnish