]> andersk Git - moira.git/blobdiff - gen/nagios-wsh.gen
Command line printer manipulation client, and build goo.
[moira.git] / gen / nagios-wsh.gen
index 3700360d7f728cccc3ff27e96ed5c58814a0af8e..5a2e7f68742aab7f6cc51dcbd8b0da165f5c3836 100755 (executable)
@@ -40,6 +40,7 @@ define host{
        host_name               $name
        alias                   $name
        address                 $name
+       contact_groups          wsh
        use                     generic-host
        }
 
@@ -80,11 +81,12 @@ END
        while (<@tags>) {
            my $service = $_;
            chomp $service;
-           if ($service =~ /^(FTP|NFS|HTTP|HTTPS|SMTP|SSHD|TELNET|TNS)$/i) {
+           if ($service =~ /^(FTP|NFS|HTTP|HTTPS|SMTP|SSHD|TELNET|TNS|WINDOWS-UPTIME)$/i) {
                my $ucservice = $service;
                $ucservice =~ tr/a-z/A-Z/;
                my $lcservice = $service;
                $lcservice =~ tr/A-Z/a-z/;
+               next if $services{$ucservice};
                $services{$ucservice}++;
                print OUT <<END;
 define service{
@@ -104,6 +106,7 @@ define serviceescalation{
 
 END
            } elsif ($service =~ /^HTTPS-CERT$/i) {
+               next if $services{'HTTPS-CERT'};
                $services{'HTTPS-CERT'}++;
                print OUT <<END;
 define service{
@@ -113,12 +116,82 @@ define service{
         }
 
 END
-           } else {
-               printf STDERR "Machine %s has unknown service %s; ignoring\n", $name, $service;
-           }
+           } else { # Hopefully this is a URL of some sort
+               my $protocol;
+               my $server;
+               my $path;
+               if ($service =~ /^([a-z]*):\/\/([^\/]*)(.*)$/ ) {
+                   $protocol = $1;
+                   $server = $2;
+                   $path = $3;
+                   $protocol =~ tr/a-z/A-Z/;
+                   $server =~ tr/A-Z/a-z/;
+               }
+               if ($protocol =~ /^HTTP(|S)$/) {
+                   $path = "/" if ($path eq "");
+                   if ($server eq $name && $path eq "/") { # this is a simple service
+                       push @tags,$protocol;
+                   }
+                   # prep a bunch of variables for the text we'll spit out
+                   my $description = "$protocol-$server-$path";
+                   $description =~ tr/A-Z/a-z/;
+                   next if $services{$description};
+                   $services{$description}++;
+                   $description =~ s/-\//-/g;
+                   $description =~ s/\/-/-/g;
+                   $description =~ s/\//-/g;
+                   $description =~ s/-$//g;
+                   my $ucdescription = $description;
+                   $ucdescription =~ tr/a-z/A-Z/;
+                   my $SSL = "";
+                   if ($protocol eq "HTTPS") {
+                       $SSL = "--SSL -k /var/nagios/etc/cert.pem";
+                   }
+                   print OUT <<END;
+define command{
+       command_name    check_$name-$description
+       command_line    \$USER1\$/check_http -H $server $SSL -u $path
+       }
 
-           if ($services{'HTTPS'} && $services{'HTTPS-CERT'}) {
-               print OUT <<END;
+define service{
+       host_name               $name
+       name                    $description-service
+       service_description     $ucdescription
+       contact_groups          wsh
+       check_command           check_$name-$description
+       use                     generic-service
+       }
+
+define serviceescalation{
+       host_name               $name
+       contact_groups          wsh,wsh-mail
+       service_description     $ucdescription
+       first_notification      2
+       last_notification       0
+       notification_interval   0
+       }
+
+END
+                   if ($services{$protocol} && $name eq $server) {
+                   print OUT <<END;
+define servicedependency{
+       dependent_host_name             $name
+       dependent_service_description   $ucdescription
+       host_name                       $name
+       service_description             $protocol
+       execution_failure_criteria      n
+       notification_failure_criteria   w,u,c
+       }
+
+END
+                   }
+               } else {
+                   printf STDERR "Machine %s has unknown service %s; ignoring\n", $name, $service;
+               }
+           }  # if SERVICE else URL
+       } # while @tags
+       if ($services{'HTTPS'} && $services{'HTTPS-CERT'}) {
+           print OUT <<END;
 define servicedependency{
        dependent_host_name             $name
        dependent_service_description   HTTPS-CERT
@@ -129,7 +202,6 @@ define servicedependency{
        }
 
 END
-           }
        }
     } # while $sth->fetchrow_array
 
@@ -137,7 +209,6 @@ END
 define hostgroup{
         hostgroup_name          wsh-hosts
         alias                   wsh-hosts
-        contact_groups          wsh
 END
 
 print OUT "\tmembers\t\t\t";
This page took 0.0318 seconds and 4 git commands to generate.