]> andersk Git - moira.git/commitdiff
allow for simple service monitoring via tagged members
authorjweiss <jweiss>
Fri, 1 Feb 2008 17:11:44 +0000 (17:11 +0000)
committerjweiss <jweiss>
Fri, 1 Feb 2008 17:11:44 +0000 (17:11 +0000)
gen/nagios-wsh.gen

index 2b6567d0174457a0fc2b015efbc2c4027ae634d4..3700360d7f728cccc3ff27e96ed5c58814a0af8e 100755 (executable)
@@ -24,14 +24,14 @@ while (($root_list_id, $hostname) = $sth0->fetchrow_array) {
     umask 022;
     open(OUT, ">$outdir/$hostname") || exit $MR_OCONFIG;
     print OUT "# This file is automatically generated by Moira.  Do not edit.\n";
-    $sth = $dbh->prepare("SELECT m.name FROM machine m, imembers i " .
+    $sth = $dbh->prepare("SELECT m.name, i.tag FROM machine m, imembers i " .
                         "WHERE i.list_id = " . $dbh->quote($root_list_id) .
                         "AND i.member_type = 'MACHINE' AND m.status = 1 " .
                         "AND i.member_id = m.mach_id AND i.direct = 1 ORDER BY m.name") 
        || exit $MR_DBMS_ERR;
     $sth->execute;
 
-    while (($name) = $sth->fetchrow_array) {
+    while (($name, $tag) = $sth->fetchrow_array) {
        next if $name eq "[NONE]";
        $name = lc($name);
        push(@allwshhosts, $name);
@@ -68,7 +68,70 @@ define serviceescalation{
 
 END
 
-    }
+       next if $tag == 0; 
+       $sth1 = $dbh->prepare("SELECT s.string " .
+                             "FROM strings s " .
+                             "WHERE s.string_id = " . $tag)
+           || exit $MR_DBMS_ERR;
+       $sth1->execute;
+       my @tags = split /\s+/,$sth1->fetchrow_array;
+       $sth1->finish;
+       my %services;
+       while (<@tags>) {
+           my $service = $_;
+           chomp $service;
+           if ($service =~ /^(FTP|NFS|HTTP|HTTPS|SMTP|SSHD|TELNET|TNS)$/i) {
+               my $ucservice = $service;
+               $ucservice =~ tr/a-z/A-Z/;
+               my $lcservice = $service;
+               $lcservice =~ tr/A-Z/a-z/;
+               $services{$ucservice}++;
+               print OUT <<END;
+define service{
+       host_name               $name
+       contact_groups          wsh
+       use                     $lcservice-service
+       }
+
+define serviceescalation{
+       host_name               $name
+       contact_groups          wsh,wsh-mail
+       service_description     $ucservice
+       first_notification      2
+       last_notification       0
+       notification_interval   0
+       }
+
+END
+           } elsif ($service =~ /^HTTPS-CERT$/i) {
+               $services{'HTTPS-CERT'}++;
+               print OUT <<END;
+define service{
+        host_name               $name
+        contact_groups          wsh-mail
+        use                     https-cert-service
+        }
+
+END
+           } else {
+               printf STDERR "Machine %s has unknown service %s; ignoring\n", $name, $service;
+           }
+
+           if ($services{'HTTPS'} && $services{'HTTPS-CERT'}) {
+               print OUT <<END;
+define servicedependency{
+       dependent_host_name             $name
+       dependent_service_description   HTTPS-CERT
+       host_name                       $name
+       service_description             HTTPS
+       execution_failure_criteria      n
+       notification_failure_criteria   w,u,c
+       }
+
+END
+           }
+       }
+    } # while $sth->fetchrow_array
 
     print OUT <<END;
 define hostgroup{
This page took 0.04194 seconds and 5 git commands to generate.