]> andersk Git - moira.git/blame - gen/nagios-cluster.gen
Command line printer manipulation client, and build goo.
[moira.git] / gen / nagios-cluster.gen
CommitLineData
775cb4ca 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-cluster.out';
10
11use DBI;
12
13umask 022;
14open(OUT, ">$outfile") || exit $MR_OCONFIG;
15print 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
28my %clusters;
29while (($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";
41define host{
42 host_name $name
43 alias $name
44 address $name
45 contact_groups noone
46 use generic-host
47 }
48
49define service{
50 host_name $name
51 contact_groups noone
52 use ping-service
53 }
54
55define service{
56 host_name $name
57 contact_groups noone
58 use no-ssh-service
59 }
60
61define service{
62 host_name $name
63 contact_groups noone
64 use no-telnet-service
65 }
66
67define service{
68 host_name $name
69 contact_groups noone
70 use no-ftp-service
71 }
72
73define service{
74 host_name $name
75 contact_groups noone
76 use public-service
77 }
78
79END
80}
81
82foreach $key (sort (keys %clusters)) {
83 print OUT <<END;
84define hostgroup {
85 hostgroup_name $key
86 alias $key
87END
88 print OUT "\tmembers\t\t";
89 $maybecomma = "";
90 foreach $machine (@$key) {
91 print OUT "$maybecomma$machine";
92 $maybecomma = ",";
93 }
94 print OUT "\n\t}\n\n";
95}
96
97
98print OUT "\n### Printers\n\n";
99
727e75b7 100$sth0 = $dbh->prepare("SELECT UNIQUE m.name FROM machine m, printers p " .
775cb4ca 101 "WHERE (p.type = 'DORM' OR p.type ='CLUSTER') " .
102 "AND p.mach_id = m.mach_id AND m.status=1")
103 || exit $MR_DBMS_ERR;
104
105$sth0->execute || exit $MR_DBMS_ERR;
106
107while (($name) = $sth0->fetchrow_array) {
108 next if $name eq "[NONE]";
109 $name = lc($name);
110 push(@allprinters, $name);
111 print OUT <<"END";
112define host{
113 host_name $name
114 alias $name
115 address $name
116 contact_groups noone
117 use generic-host
118 }
119
120define service{
121 host_name $name
122 contact_groups noone
123 use ping-service
124 }
125
126define service{
127 host_name $name
128 contact_groups noone
129 use hpjd-service
130 }
131
132END
133
134}
135
136print OUT <<END;
137define hostgroup{
138 hostgroup_name printers
139 alias printers
140END
141
142print OUT "\tmembers\t\t";
143
144$maybecomma = "";
145foreach $printer (@allprinters) {
146 print OUT "$maybecomma$printer";
147 $maybecomma = ",";
148}
149
150print OUT "\n\t}\n\n";
151
152close(OUT);
153$dbh->disconnect;
154
155exit 0;
This page took 0.133763 seconds and 5 git commands to generate.