]>
Commit | Line | Data |
---|---|---|
a1d1b496 | 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 | $outfile = '/moira/dcm/nagios-printers.out'; | |
10 | ||
11 | use DBI; | |
12 | ||
13 | $dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira") | |
14 | || exit $MR_DBMS_ERR; | |
15 | ||
16 | $sth = $dbh->prepare("SELECT m.name FROM machine m, printers p " . | |
17 | "WHERE (p.type = 'DORM' OR p.type ='CLUSTER') " . | |
b06dd0d3 | 18 | "AND p.mach_id = m.mach_id AND m.status=1") |
a1d1b496 | 19 | || exit $MR_DBMS_ERR; |
20 | ||
21 | $sth->execute || exit $MR_DBMS_ERR; | |
22 | ||
23 | umask 022; | |
24 | open(OUT, ">$outfile") || exit $MR_OCONFIG; | |
25 | print OUT "# This File is automatically generated by Moira. Do not edit.\n"; | |
26 | ||
27 | while (($name) = $sth->fetchrow_array) { | |
28 | next if $name eq "[NONE]"; | |
29 | $name = lc($name); | |
30 | push(@allprinters, $name); | |
31 | print OUT <<"END"; | |
32 | define host{ | |
33 | host_name $name | |
34 | alias $name | |
35 | address $name | |
36 | use generic-host | |
37 | } | |
38 | ||
39 | define service{ | |
40 | host_name $name | |
41 | contact_groups ops-printers | |
42 | use ping-service | |
43 | } | |
44 | ||
45 | define service{ | |
46 | host_name $name | |
47 | contact_groups ops-printers | |
48 | use hpjd-service | |
49 | } | |
50 | ||
51 | define hostescalation{ | |
52 | host_name $name | |
53 | contact_groups ops-printers | |
54 | first_notification 2 | |
55 | last_notification 0 | |
56 | notification_interval 0 | |
57 | } | |
58 | ||
59 | define serviceescalation{ | |
60 | host_name $name | |
61 | contact_groups ops-printers | |
62 | service_description PING | |
63 | first_notification 2 | |
64 | last_notification 0 | |
65 | notification_interval 0 | |
66 | } | |
67 | ||
68 | define serviceescalation{ | |
69 | host_name $name | |
70 | contact_groups ops-printers | |
71 | service_description HPJD | |
72 | first_notification 2 | |
73 | last_notification 0 | |
74 | notification_interval 0 | |
75 | } | |
76 | ||
77 | END | |
78 | ||
79 | } | |
80 | ||
81 | print OUT <<END; | |
82 | define hostgroup{ | |
83 | hostgroup_name printers | |
84 | alias printers | |
85 | contact_groups ops-printers | |
86 | END | |
87 | ||
88 | print OUT "\tmembers\t\t"; | |
89 | ||
90 | $maybecomma = ""; | |
91 | foreach $printer (@allprinters) { | |
92 | print OUT "$maybecomma$printer"; | |
93 | $maybecomma = ","; | |
94 | } | |
95 | ||
96 | print OUT "\n\t}\n\n"; | |
97 | ||
98 | close(OUT); | |
99 | $dbh->disconnect; | |
100 | ||
101 | exit 0; |