4 # The following exit codes are defined and MUST BE CONSISTENT with the
5 # error codes the library uses:
6 $MR_DBMS_ERR = 47836421;
7 $MR_OCONFIG = 47836460;
9 $outdir = '/moira/dcm/nagios-wsh';
13 $dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
16 $sth0 = $dbh->prepare("SELECT l.list_id, m.name " .
17 "FROM list l, machine m, serverhosts sh " .
18 "WHERE sh.value3 = l.name AND sh.service = " .
19 "'NAGIOS-WSH' AND m.mach_id = sh.mach_id")
23 while (($root_list_id, $hostname) = $sth0->fetchrow_array) {
25 open(OUT, ">$outdir/$hostname") || exit $MR_OCONFIG;
26 print OUT "# This file is automatically generated by Moira. Do not edit.\n";
27 $sth = $dbh->prepare("SELECT m.name, i.tag FROM machine m, imembers i " .
28 "WHERE i.list_id = " . $dbh->quote($root_list_id) .
29 "AND i.member_type = 'MACHINE' AND m.status = 1 " .
30 "AND i.member_id = m.mach_id AND i.direct = 1 ORDER BY m.name")
34 while (($name, $tag) = $sth->fetchrow_array) {
35 next if $name eq "[NONE]";
37 push(@allwshhosts, $name);
53 define hostescalation{
55 contact_groups wsh,wsh-mail
58 notification_interval 0
61 define serviceescalation{
63 contact_groups wsh,wsh-mail
64 service_description PING
67 notification_interval 0
73 $sth1 = $dbh->prepare("SELECT s.string " .
75 "WHERE s.string_id = " . $tag)
78 my @tags = split /\s+/,$sth1->fetchrow_array;
84 if ($service =~ /^(FTP|NFS|HTTP|HTTPS|SMTP|SSHD|TELNET|TNS)$/i) {
85 my $ucservice = $service;
86 $ucservice =~ tr/a-z/A-Z/;
87 my $lcservice = $service;
88 $lcservice =~ tr/A-Z/a-z/;
89 next if $services{$ucservice};
90 $services{$ucservice}++;
95 use $lcservice-service
98 define serviceescalation{
100 contact_groups wsh,wsh-mail
101 service_description $ucservice
104 notification_interval 0
108 } elsif ($service =~ /^HTTPS-CERT$/i) {
109 next if $services{'HTTPS-CERT'};
110 $services{'HTTPS-CERT'}++;
114 contact_groups wsh-mail
115 use https-cert-service
119 } else { # Hopefully this is a URL of some sort
123 if ($service =~ /^([a-z]*):\/\/([^\/]*)(.*)$/ ) {
127 $protocol =~ tr/a-z/A-Z/;
128 $server =~ tr/A-Z/a-z/;
130 if ($protocol =~ /^HTTP(|S)$/) {
131 $path = "/" if ($path eq "");
132 if ($server eq $name && $path eq "/") { # this is a simple service
133 push @tags,$protocol;
135 # prep a bunch of variables for the text we'll spit out
136 my $description = "$protocol-$server-$path";
137 $description =~ tr/A-Z/a-z/;
138 next if $services{$description};
139 $services{$description}++;
140 $description =~ s/-\//-/g;
141 $description =~ s/\/-/-/g;
142 $description =~ s/\//-/g;
143 $description =~ s/-$//g;
144 my $ucdescription = $description;
145 $ucdescription =~ tr/a-z/A-Z/;
147 if ($protocol eq "HTTPS") {
148 $SSL = "--SSL -k /var/nagios/etc/cert.pem";
152 command_name check_$name-$description
153 command_line \$USER1\$/check_http -H $server $SSL -u $path
158 name $description-service
159 service_description $ucdescription
161 check_command check_$name-$description
165 define serviceescalation{
167 contact_groups wsh,wsh-mail
168 service_description $ucdescription
171 notification_interval 0
175 if ($services{$protocol} && $name eq $server) {
177 define servicedependency{
178 dependent_host_name $name
179 dependent_service_description $ucdescription
181 service_description $protocol
182 execution_failure_criteria n
183 notification_failure_criteria w,u,c
189 printf STDERR "Machine %s has unknown service %s; ignoring\n", $name, $service;
191 } # if SERVICE else URL
193 if ($services{'HTTPS'} && $services{'HTTPS-CERT'}) {
195 define servicedependency{
196 dependent_host_name $name
197 dependent_service_description HTTPS-CERT
199 service_description HTTPS
200 execution_failure_criteria n
201 notification_failure_criteria w,u,c
206 } # while $sth->fetchrow_array
210 hostgroup_name wsh-hosts
214 print OUT "\tmembers\t\t\t";
217 foreach $host (@allwshhosts) {
218 print OUT "$maybecomma$host";
222 print OUT "\n\t}\n\n";