Adding Nagios check for OpenSRF diagnostics
authorChris Sharp <csharp@georgialibraries.org>
Fri, 4 Aug 2017 17:52:53 +0000 (13:52 -0400)
committerChris Sharp <csharp@georgialibraries.org>
Fri, 4 Aug 2017 17:52:53 +0000 (13:52 -0400)
nagios/check_osrf [new file with mode: 0755]

diff --git a/nagios/check_osrf b/nagios/check_osrf
new file mode 100755 (executable)
index 0000000..395d107
--- /dev/null
@@ -0,0 +1,48 @@
+#!/usr/bin/perl
+
+# Copyright (C) 2017 Georgia Public Library Service
+# Chris Sharp <csharp@georgialibraries.org>
+#
+# Nagios/Icinga check for OpenSRF Diagnostic
+#
+# Returns OK as long as all configured services are running.
+#
+# Installation: 
+# 
+# Copy to your Nagios plugins directory (typically /usr/lib/nagios/plugins) on
+# the remote server.  Create the command in npre_local.cfg with sudo.  Example:
+#      
+#      command[check_osrf]=sudo /usr/lib/nagios/plugins/check_osrf
+#
+# Then allow the nagios user to run the command on opensrf's behalf by adding 
+# the following line using visudo:
+#
+# nagios ALL=(root)  NOPASSWD: /usr/lib/nagios/plugins/check_osrf
+#
+# adjusting for the actual location of your Nagios plugins.
+
+use warnings;
+use strict;
+use Getopt::Long;
+
+my $osrf_bindir = "/openils/bin";
+my $osrf_user = "opensrf";
+my $localhost = '';
+my $command;
+my @errors;
+GetOptions( 'localhost' => \$localhost );
+
+if ($localhost) {
+       $command = "\"$osrf_bindir/osrf_control --localhost --diagnostic | grep ERR\"";
+} else {
+       $command = "\"$osrf_bindir/osrf_control --diagnostic | grep ERR\"";
+}
+
+@errors = `su - $osrf_user -c $command`;
+
+if (@errors) {
+       print "CRITICAL: At least one configured OpenSRF service not running!:\n@errors\n";
+} else {
+       print "OK: All configured OpenSRF services running.\n";
+}
+