[23740] | 1 | #!/moira/bin/perl -Tw |
---|
| 2 | |
---|
[25455] | 3 | # $Id: nagios-cluster.gen 4054 2011-10-02 15:55:43Z zacheiss $ |
---|
[23740] | 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 | |
---|
[25198] | 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 | |
---|
[25388] | 91 | define service{ |
---|
| 92 | host_name $name |
---|
| 93 | contact_groups noone |
---|
| 94 | use usbhid-service |
---|
| 95 | } |
---|
| 96 | |
---|
[23740] | 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 | |
---|
[23882] | 118 | $sth0 = $dbh->prepare("SELECT UNIQUE m.name FROM machine m, printers p " . |
---|
[25455] | 119 | "WHERE (p.type = 'DORM' OR p.type ='CLUSTER') " . |
---|
| 120 | "AND p.mach_id = m.mach_id AND m.status=1 " . |
---|
| 121 | "AND (p.status = 1 OR p.status = 4)") |
---|
[23740] | 122 | || exit $MR_DBMS_ERR; |
---|
| 123 | |
---|
| 124 | $sth0->execute || exit $MR_DBMS_ERR; |
---|
| 125 | |
---|
| 126 | while (($name) = $sth0->fetchrow_array) { |
---|
| 127 | next if $name eq "[NONE]"; |
---|
| 128 | $name = lc($name); |
---|
| 129 | push(@allprinters, $name); |
---|
| 130 | print OUT <<"END"; |
---|
| 131 | define host{ |
---|
| 132 | host_name $name |
---|
| 133 | alias $name |
---|
| 134 | address $name |
---|
| 135 | contact_groups noone |
---|
| 136 | use generic-host |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | define service{ |
---|
| 140 | host_name $name |
---|
| 141 | contact_groups noone |
---|
| 142 | use ping-service |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | define service{ |
---|
| 146 | host_name $name |
---|
| 147 | contact_groups noone |
---|
| 148 | use hpjd-service |
---|
| 149 | } |
---|
| 150 | |
---|
[25455] | 151 | define service{ |
---|
| 152 | host_name $name |
---|
| 153 | contact_groups noone |
---|
| 154 | use ipacl-service |
---|
| 155 | } |
---|
| 156 | |
---|
[23740] | 157 | END |
---|
| 158 | |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | print OUT <<END; |
---|
| 162 | define hostgroup{ |
---|
| 163 | hostgroup_name printers |
---|
| 164 | alias printers |
---|
| 165 | END |
---|
| 166 | |
---|
| 167 | print OUT "\tmembers\t\t"; |
---|
| 168 | |
---|
| 169 | $maybecomma = ""; |
---|
| 170 | foreach $printer (@allprinters) { |
---|
| 171 | print OUT "$maybecomma$printer"; |
---|
| 172 | $maybecomma = ","; |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | print OUT "\n\t}\n\n"; |
---|
| 176 | |
---|
| 177 | close(OUT); |
---|
| 178 | $dbh->disconnect; |
---|
| 179 | |
---|
| 180 | exit 0; |
---|