need a nagios alert script to check irspy updates, IR-336
authorWolfram Schneider <wosch@indexdata.dk>
Mon, 18 Mar 2013 11:09:43 +0000 (11:09 +0000)
committerWolfram Schneider <wosch@indexdata.dk>
Mon, 18 Mar 2013 11:09:43 +0000 (11:09 +0000)
Changes
bin/irspy-nagios.pl [new file with mode: 0755]

diff --git a/Changes b/Changes
index 921b9b5..227f333 100644 (file)
--- a/Changes
+++ b/Changes
@@ -32,6 +32,7 @@ Revision history for Perl extension ZOOM::IRSpy.
          from distribution entirely in a subsequent release.
        - Support new "irspy_data" log-level to register information
          written to target description record.
          from distribution entirely in a subsequent release.
        - Support new "irspy_data" log-level to register information
          written to target description record.
+       - need a nagios alert script to check irspy updates, IR-336
 
 1.02  Wed Jul  7 16:43:36 BST 2010
        - Enhance setrlimit program so that it can set maximum
 
 1.02  Wed Jul  7 16:43:36 BST 2010
        - Enhance setrlimit program so that it can set maximum
diff --git a/bin/irspy-nagios.pl b/bin/irspy-nagios.pl
new file mode 100755 (executable)
index 0000000..8ec764b
--- /dev/null
@@ -0,0 +1,61 @@
+#!/usr/bin/perl
+# Copyright (c) 2013 IndexData ApS, http://indexdata.com
+#
+# irspy-nagios.pl - check if IRSpy updates run
+
+use strict;
+use warnings;
+
+use LWP::Simple;
+use HTTP::Date;
+use Getopt::Long;
+
+my $help;
+my $debug = 0;
+my $update_cycle_days = 7;
+my $url = 'http://irspy.indexdata.com/raw.html?id=Z39.50%3Aopencontent.indexdata.com%3A210%2Foaister';
+
+sub usage () {
+    <<EOF;
+usage: $0 [ options ]
+
+--debug=0..2            debug option, default: $debug
+--days=1..7            alert if older than days, default $update_cycle_days
+--url=URL              url to check, default $url
+
+EOF
+}
+
+
+##################################################################
+# main
+#
+GetOptions(
+    "debug=i"                  => \$debug,
+    "days=i"              => \$update_cycle_days,
+    "url=s"       => \$url,
+) or die usage;
+die usage if $help;
+
+my $data = get $url;
+
+die "No data for $url\n" if !defined $data;
+warn $data if $debug >= 2;
+
+if ($data =~ m,<dateModified>(.*?)</dateModified>,) {
+  my $date = $1;
+  my $time = str2time($date);
+
+  my $last_update =  time() - $time;
+  warn "last update: $last_update seconds ago\n" if $debug;
+
+  if ($last_update > 24*3600* $update_cycle_days) {
+       die "Last update is older than $last_update seconds: $date\n";
+  }
+
+} else {
+   die "cannot parse date field <dateModified> from $url\n";
+}
+
+exit 0;
+