1 | #!/moira/bin/perl -Tw |
---|
2 | |
---|
3 | # $Id: nagios-cluster.gen 4047 2011-08-22 21:04:03Z jweiss $ |
---|
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-cluster.out'; |
---|
10 | |
---|
11 | use DBI; |
---|
12 | |
---|
13 | umask 022; |
---|
14 | open(OUT, ">$outfile") || exit $MR_OCONFIG; |
---|
15 | print OUT "# This File is automatically generated by Moira. Do not edit.\n\n"; |
---|
16 | |
---|
17 | |
---|
18 | $dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira") |
---|
19 | || exit $MR_DBMS_ERR; |
---|
20 | |
---|
21 | |
---|
22 | $sth1 = $dbh->prepare("SELECT m.name FROM machine m, clusters c, mcmap p " . |
---|
23 | "WHERE m.status=1 AND c.name='cluster' AND " . |
---|
24 | "(m.mach_id=p.mach_id AND p.clu_id=c.clu_id)") |
---|
25 | || exit $MR_DBMS_ERR; |
---|
26 | $sth1->execute || exit $MR_DBMS_ERR; |
---|
27 | |
---|
28 | my %clusters; |
---|
29 | while (($name) = $sth1->fetchrow_array) { |
---|
30 | next if $name eq "[NONE]"; |
---|
31 | $name = lc($name); |
---|
32 | my $cluster = $name; |
---|
33 | $cluster =~ s/\..*$//; |
---|
34 | $cluster =~ s/\-[^\-]*$//; |
---|
35 | # print "$name\t$cluster\n"; |
---|
36 | push @$cluster, $name; |
---|
37 | $clusters{$cluster}++; |
---|
38 | |
---|
39 | |
---|
40 | print OUT <<"END"; |
---|
41 | define host{ |
---|
42 | host_name $name |
---|
43 | alias $name |
---|
44 | address $name |
---|
45 | contact_groups noone |
---|
46 | use generic-host |
---|
47 | } |
---|
48 | |
---|
49 | define service{ |
---|
50 | host_name $name |
---|
51 | contact_groups noone |
---|
52 | use ping-service |
---|
53 | } |
---|
54 | |
---|
55 | define service{ |
---|
56 | host_name $name |
---|
57 | contact_groups noone |
---|
58 | use no-ssh-service |
---|
59 | } |
---|
60 | |
---|
61 | define service{ |
---|
62 | host_name $name |
---|
63 | contact_groups noone |
---|
64 | use no-telnet-service |
---|
65 | } |
---|
66 | |
---|
67 | define service{ |
---|
68 | host_name $name |
---|
69 | contact_groups noone |
---|
70 | use no-ftp-service |
---|
71 | } |
---|
72 | |
---|
73 | define service{ |
---|
74 | host_name $name |
---|
75 | contact_groups noone |
---|
76 | use public-service |
---|
77 | } |
---|
78 | |
---|
79 | define service{ |
---|
80 | host_name $name |
---|
81 | contact_groups noone |
---|
82 | use update-service |
---|
83 | } |
---|
84 | |
---|
85 | define service{ |
---|
86 | host_name $name |
---|
87 | contact_groups noone |
---|
88 | use modules-service |
---|
89 | } |
---|
90 | |
---|
91 | define service{ |
---|
92 | host_name $name |
---|
93 | contact_groups noone |
---|
94 | use usbhid-service |
---|
95 | } |
---|
96 | |
---|
97 | END |
---|
98 | } |
---|
99 | |
---|
100 | foreach $key (sort (keys %clusters)) { |
---|
101 | print OUT <<END; |
---|
102 | define hostgroup { |
---|
103 | hostgroup_name $key |
---|
104 | alias $key |
---|
105 | END |
---|
106 | print OUT "\tmembers\t\t"; |
---|
107 | $maybecomma = ""; |
---|
108 | foreach $machine (@$key) { |
---|
109 | print OUT "$maybecomma$machine"; |
---|
110 | $maybecomma = ","; |
---|
111 | } |
---|
112 | print OUT "\n\t}\n\n"; |
---|
113 | } |
---|
114 | |
---|
115 | |
---|
116 | print OUT "\n### Printers\n\n"; |
---|
117 | |
---|
118 | $sth0 = $dbh->prepare("SELECT UNIQUE m.name FROM machine m, printers p " . |
---|
119 | "WHERE (p.type = 'DORM' OR p.type ='CLUSTER') " . |
---|
120 | "AND p.mach_id = m.mach_id AND m.status=1") |
---|
121 | || exit $MR_DBMS_ERR; |
---|
122 | |
---|
123 | $sth0->execute || exit $MR_DBMS_ERR; |
---|
124 | |
---|
125 | while (($name) = $sth0->fetchrow_array) { |
---|
126 | next if $name eq "[NONE]"; |
---|
127 | $name = lc($name); |
---|
128 | push(@allprinters, $name); |
---|
129 | print OUT <<"END"; |
---|
130 | define host{ |
---|
131 | host_name $name |
---|
132 | alias $name |
---|
133 | address $name |
---|
134 | contact_groups noone |
---|
135 | use generic-host |
---|
136 | } |
---|
137 | |
---|
138 | define service{ |
---|
139 | host_name $name |
---|
140 | contact_groups noone |
---|
141 | use ping-service |
---|
142 | } |
---|
143 | |
---|
144 | define service{ |
---|
145 | host_name $name |
---|
146 | contact_groups noone |
---|
147 | use hpjd-service |
---|
148 | } |
---|
149 | |
---|
150 | END |
---|
151 | |
---|
152 | } |
---|
153 | |
---|
154 | print OUT <<END; |
---|
155 | define hostgroup{ |
---|
156 | hostgroup_name printers |
---|
157 | alias printers |
---|
158 | END |
---|
159 | |
---|
160 | print OUT "\tmembers\t\t"; |
---|
161 | |
---|
162 | $maybecomma = ""; |
---|
163 | foreach $printer (@allprinters) { |
---|
164 | print OUT "$maybecomma$printer"; |
---|
165 | $maybecomma = ","; |
---|
166 | } |
---|
167 | |
---|
168 | print OUT "\n\t}\n\n"; |
---|
169 | |
---|
170 | close(OUT); |
---|
171 | $dbh->disconnect; |
---|
172 | |
---|
173 | exit 0; |
---|