]> andersk Git - moira.git/commitdiff
nagios-cluster support for monitoring the machines in addition to the printers
authorjweiss <jweiss>
Wed, 18 Feb 2009 00:55:00 +0000 (00:55 +0000)
committerjweiss <jweiss>
Wed, 18 Feb 2009 00:55:00 +0000 (00:55 +0000)
should eventually replace nagios-printers

gen/Makefile.in
gen/nagios-cluster.gen [new file with mode: 0755]
gen/nagios-cluster.sh [new file with mode: 0644]

index 315a2256cfe50acb8768b5a4826e0fbc2e3a0a01..0f375dbde5f8a1f3924899df388b3481a2bf58e3 100644 (file)
@@ -46,7 +46,8 @@ TARGET=       acl.gen boot.gen confluence.gen cups-print.gen dhcp.gen directory.gen \
 SCRIPTS=access.gen access.sh acl.sh aliases.sh boot.sh ca.gen calendar.gen \
        cups-print.sh dhcp.sh events.sh hesiod.sh ip-billing.gen \
        ip-billing.sh ldap.gen longjobs.gen longjobs.sh mailhosts.gen \
-       mailhub.sh mailman.gen mailman.sh nagios-colo.gen nagios-colo.sh \
+       mailhub.sh mailman.gen mailman.sh nagios-cluster.gen \
+       nagios-cluster.sh nagios-colo.gen nagios-colo.sh \
        nagios-printers.gen nagios-printers.sh nagios-wsh.gen nagios-wsh.sh \
        ndb.sh nfs.sh null.sh postoffice.sh print.sh rt.sh sapprint.gen \
        sapprint.sh spwatch.gen tsm.gen tsm.sh warehouse.gen warehouse.sh \
diff --git a/gen/nagios-cluster.gen b/gen/nagios-cluster.gen
new file mode 100755 (executable)
index 0000000..c283ba4
--- /dev/null
@@ -0,0 +1,155 @@
+#!/moira/bin/perl -Tw
+
+# $Id$
+# The following exit codes are defined and MUST BE CONSISTENT with the
+# error codes the library uses:
+$MR_DBMS_ERR = 47836421;
+$MR_OCONFIG = 47836460;
+
+$outfile = '/moira/dcm/nagios-cluster.out';
+
+use DBI;
+
+umask 022;
+open(OUT, ">$outfile") || exit $MR_OCONFIG;
+print OUT "# This File is automatically generated by Moira.  Do not edit.\n\n";
+
+
+$dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
+  || exit $MR_DBMS_ERR;
+
+
+$sth1 = $dbh->prepare("SELECT m.name FROM machine m, clusters c, mcmap p " .
+                    "WHERE m.status=1 AND c.name='cluster' AND " .
+                    "(m.mach_id=p.mach_id AND p.clu_id=c.clu_id)")
+    || exit $MR_DBMS_ERR;
+$sth1->execute || exit $MR_DBMS_ERR;
+
+my %clusters;
+while (($name) = $sth1->fetchrow_array) {
+    next if $name eq "[NONE]";
+    $name = lc($name);
+    my $cluster = $name;
+    $cluster =~ s/\..*$//;
+    $cluster =~ s/\-[^\-]*$//;
+#    print "$name\t$cluster\n";
+    push @$cluster, $name;
+    $clusters{$cluster}++;
+
+
+    print OUT <<"END";
+define host{
+       host_name               $name
+       alias                   $name
+       address                 $name
+       contact_groups          noone
+       use                     generic-host
+       }
+
+define service{
+       host_name               $name
+       contact_groups          noone
+       use                     ping-service
+       }
+
+define service{
+       host_name               $name
+       contact_groups          noone
+       use                     no-ssh-service
+       }
+
+define service{
+       host_name               $name
+       contact_groups          noone
+       use                     no-telnet-service
+       }
+
+define service{
+       host_name               $name
+       contact_groups          noone
+       use                     no-ftp-service
+       }
+
+define service{
+       host_name               $name
+       contact_groups          noone
+       use                     public-service
+       }
+
+END
+}
+
+foreach $key (sort (keys %clusters)) {
+    print OUT <<END;
+define hostgroup {
+       hostgroup_name          $key
+       alias                   $key
+END
+    print OUT "\tmembers\t\t";
+    $maybecomma = "";
+    foreach $machine (@$key) {
+       print OUT "$maybecomma$machine";
+       $maybecomma = ",";
+    }
+    print OUT "\n\t}\n\n";
+}
+
+
+print OUT "\n### Printers\n\n";
+
+$sth0 = $dbh->prepare("SELECT m.name FROM machine m, printers p " .
+                    "WHERE (p.type = 'DORM' OR p.type ='CLUSTER') " .
+                    "AND p.mach_id = m.mach_id AND m.status=1")
+    || exit $MR_DBMS_ERR;
+
+$sth0->execute || exit $MR_DBMS_ERR;
+
+while (($name) = $sth0->fetchrow_array) {
+    next if $name eq "[NONE]";
+    $name = lc($name);
+    push(@allprinters, $name);
+    print OUT <<"END";
+define host{
+       host_name               $name
+       alias                   $name
+       address                 $name
+       contact_groups          noone
+       use                     generic-host
+       }
+
+define service{
+       host_name               $name
+       contact_groups          noone
+       use                     ping-service
+       }
+
+define service{
+       host_name               $name
+       contact_groups          noone
+       use                     hpjd-service
+       }
+
+END
+
+}
+
+print OUT <<END;
+define hostgroup{
+       hostgroup_name          printers
+       alias                   printers
+END
+
+print OUT "\tmembers\t\t";
+
+$maybecomma = "";
+foreach $printer (@allprinters) {
+    print OUT "$maybecomma$printer";
+    $maybecomma = ",";
+}
+
+print OUT "\n\t}\n\n";
+
+close(OUT);
+$dbh->disconnect;
+
+exit 0;
diff --git a/gen/nagios-cluster.sh b/gen/nagios-cluster.sh
new file mode 100644 (file)
index 0000000..55acc1a
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/sh
+# $Id$
+
+# The following exit codes are defined and MUST BE CONSISTENT with
+# error codes the library uses:
+MR_MKCRED=47836474
+
+file=/var/nagios-cluster/etc/moira-cluster.cfg
+newfile=$file.new
+initscript=/etc/init.d/nagios-cluster
+
+if [ -d /var/athena ] && [ -w /var/athena ]; then
+    exec >/var/athena/moira_update.log 2>&1
+else 
+    exec >/tmp/moira_update.log 2>&1
+fi
+
+chmod 644 $file.new
+diff -q $file $newfile
+status=$?
+if [ $status -eq 0 ]; then
+    echo "No changes"
+    exit 0
+elif [ $status -eq 1 ]; then
+    mv $newfile $file
+    $initscript restart
+    if [ $? -eq 0 ]; then 
+       exit 0
+    else
+       exit $MR_MKCRED
+    fi
+else
+    exit $MR_MKCRED
+fi
This page took 0.049278 seconds and 5 git commands to generate.