]> andersk Git - moira.git/blame - gen/nagios-wsh.gen
Don't FixCase() first, middle, or last names.
[moira.git] / gen / nagios-wsh.gen
CommitLineData
522d1836 1#!/moira/bin/perl -Tw
2
3# $Id$
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;
8
9$outdir = '/moira/dcm/nagios-wsh';
10
11use DBI;
12
13$dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
14 || exit $MR_DBMS_ERR;
15
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")
20 || exit $MR_DBMS_ERR;
21$sth0->execute;
22
23while (($root_list_id, $hostname) = $sth0->fetchrow_array) {
24 umask 022;
25 open(OUT, ">$outdir/$hostname") || exit $MR_OCONFIG;
26 print OUT "# This file is automatically generated by Moira. Do not edit.\n";
c21d764b 27 $sth = $dbh->prepare("SELECT m.name, i.tag FROM machine m, imembers i " .
522d1836 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")
31 || exit $MR_DBMS_ERR;
32 $sth->execute;
33
c21d764b 34 while (($name, $tag) = $sth->fetchrow_array) {
522d1836 35 next if $name eq "[NONE]";
36 $name = lc($name);
37 push(@allwshhosts, $name);
38 print OUT <<END;
39define host{
40 host_name $name
41 alias $name
42 address $name
43 use generic-host
44 }
45
46define service{
47 host_name $name
48 contact_groups wsh
49 use ping-service
50 }
51
52define hostescalation{
53 host_name $name
54 contact_groups wsh,wsh-mail
55 first_notification 2
56 last_notification 0
57 notification_interval 0
58 }
59
60define serviceescalation{
61 host_name $name
62 contact_groups wsh,wsh-mail
63 service_description PING
64 first_notification 2
65 last_notification 0
66 notification_interval 0
67 }
68
69END
70
c21d764b 71 next if $tag == 0;
72 $sth1 = $dbh->prepare("SELECT s.string " .
73 "FROM strings s " .
74 "WHERE s.string_id = " . $tag)
75 || exit $MR_DBMS_ERR;
76 $sth1->execute;
77 my @tags = split /\s+/,$sth1->fetchrow_array;
78 $sth1->finish;
79 my %services;
80 while (<@tags>) {
81 my $service = $_;
82 chomp $service;
83 if ($service =~ /^(FTP|NFS|HTTP|HTTPS|SMTP|SSHD|TELNET|TNS)$/i) {
84 my $ucservice = $service;
85 $ucservice =~ tr/a-z/A-Z/;
86 my $lcservice = $service;
87 $lcservice =~ tr/A-Z/a-z/;
64497905 88 next if $services{$ucservice};
c21d764b 89 $services{$ucservice}++;
90 print OUT <<END;
91define service{
92 host_name $name
93 contact_groups wsh
94 use $lcservice-service
95 }
96
97define serviceescalation{
98 host_name $name
99 contact_groups wsh,wsh-mail
100 service_description $ucservice
101 first_notification 2
102 last_notification 0
103 notification_interval 0
104 }
105
106END
107 } elsif ($service =~ /^HTTPS-CERT$/i) {
64497905 108 next if $services{'HTTPS-CERT'};
c21d764b 109 $services{'HTTPS-CERT'}++;
110 print OUT <<END;
111define service{
112 host_name $name
113 contact_groups wsh-mail
114 use https-cert-service
115 }
116
117END
e5ac2c18 118 } else { # Hopefully this is a URL of some sort
119 my $protocol;
120 my $server;
121 my $path;
122 if ($service =~ /^([a-z]*):\/\/([^\/]*)(.*)$/ ) {
123 $protocol = $1;
124 $server = $2;
125 $path = $3;
126 $protocol =~ tr/a-z/A-Z/;
127 $server =~ tr/A-Z/a-z/;
128 }
129 if ($protocol =~ /^HTTP(|S)$/) {
130 $path = "/" if ($path eq "");
131 if ($server eq $name && $path eq "/") { # this is a simple service
132 push @tags,$protocol;
133 }
134 # prep a bunch of variables for the text we'll spit out
135 my $description = "$protocol-$server-$path";
64497905 136 $description =~ tr/A-Z/a-z/;
137 next if $services{$description};
138 $services{$description}++;
e5ac2c18 139 $description =~ s/-\//-/g;
140 $description =~ s/\/-/-/g;
141 $description =~ s/\//-/g;
142 $description =~ s/-$//g;
e5ac2c18 143 my $ucdescription = $description;
144 $ucdescription =~ tr/a-z/A-Z/;
145 my $SSL = "";
146 if ($protocol eq "HTTPS") {
147 $SSL = "--SSL -k /var/nagios/etc/cert.pem";
148 }
149 print OUT <<END;
150define command{
151 command_name check_$name-$description
152 command_line \$USER1\$/check_http -H $server $SSL -u $path
153 }
154
155define service{
156 host_name $name
157 name $description-service
158 service_description $ucdescription
159 contact_groups wsh
160 check_command check_$name-$description
161 use generic-service
162 }
163
164define serviceescalation{
165 host_name $name
166 contact_groups wsh,wsh-mail
167 service_description $ucdescription
168 first_notification 2
169 last_notification 0
170 notification_interval 0
171 }
172
173END
64497905 174 if ($services{$protocol} && $name eq $server) {
e5ac2c18 175 print OUT <<END;
176define servicedependency{
177 dependent_host_name $name
178 dependent_service_description $ucdescription
179 host_name $name
180 service_description $protocol
181 execution_failure_criteria n
182 notification_failure_criteria w,u,c
183 }
184
185END
186 }
187 } else {
188 printf STDERR "Machine %s has unknown service %s; ignoring\n", $name, $service;
189 }
190 } # if SERVICE else URL
64497905 191 } # while @tags
192 if ($services{'HTTPS'} && $services{'HTTPS-CERT'}) {
193 print OUT <<END;
c21d764b 194define servicedependency{
195 dependent_host_name $name
196 dependent_service_description HTTPS-CERT
197 host_name $name
198 service_description HTTPS
199 execution_failure_criteria n
200 notification_failure_criteria w,u,c
201 }
202
203END
c21d764b 204 }
205 } # while $sth->fetchrow_array
522d1836 206
207 print OUT <<END;
208define hostgroup{
209 hostgroup_name wsh-hosts
210 alias wsh-hosts
211 contact_groups wsh
212END
213
214print OUT "\tmembers\t\t\t";
215
216$maybecomma = "";
217foreach $host (@allwshhosts) {
218 print OUT "$maybecomma$host";
219 $maybecomma = ",";
220}
221
222print OUT "\n\t}\n\n";
223
224close(OUT);
225}
226
227$dbh->disconnect;
228
229exit 0;
230
231
This page took 0.973643 seconds and 5 git commands to generate.