]> andersk Git - moira.git/blob - gen/nagios-wsh.gen
WSH Nagios config.
[moira.git] / gen / nagios-wsh.gen
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
11 use 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
23 while (($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";
27     $sth = $dbh->prepare("SELECT m.name 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") 
31         || exit $MR_DBMS_ERR;
32     $sth->execute;
33
34     while (($name) = $sth->fetchrow_array) {
35         next if $name eq "[NONE]";
36         $name = lc($name);
37         push(@allwshhosts, $name);
38         print OUT <<END;
39 define host{
40         host_name               $name
41         alias                   $name
42         address                 $name
43         use                     generic-host
44         }
45
46 define service{
47         host_name               $name
48         contact_groups          wsh
49         use                     ping-service
50         }
51
52 define 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
60 define 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
69 END
70
71     }
72
73     print OUT <<END;
74 define hostgroup{
75         hostgroup_name          wsh-hosts
76         alias                   wsh-hosts
77         contact_groups          wsh
78 END
79
80 print OUT "\tmembers\t\t\t";
81
82 $maybecomma = "";
83 foreach $host (@allwshhosts) {
84     print OUT "$maybecomma$host";
85     $maybecomma = ",";
86 }
87
88 print OUT "\n\t}\n\n";
89
90 close(OUT);
91 }
92
93 $dbh->disconnect;
94
95 exit 0;
96
97
This page took 0.085207 seconds and 5 git commands to generate.