source: trunk/third/moira/gen/nagios-colo.gen @ 23740

Revision 23740, 2.3 KB checked in by broder, 16 years ago (diff)
In moira: * New CVS snapshot (Trac: #195) * Drop patches that have been incorporated upstream. * Update to build without krb4 on systems that no longer have it. This doesn't build yet on squeeze, which lacks a krb4 library, but I'm committing now before I start hacking away at a patch to fix that.
  • Property svn:executable set to *
Line 
1#!/moira/bin/perl -Tw
2
3# $Id: nagios-colo.gen,v 1.6 2008-04-17 17:24:36 zacheiss Exp $
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-colo';
10
11use 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-COLO' AND m.mach_id = sh.mach_id")
20    || exit $MR_DBMS_ERR;
21$sth0->execute;
22
23while (($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(@allcolohosts, $name);
38        print OUT <<END;
39define host{
40        host_name               $name
41        alias                   $name
42        address                 $name
43        contact_groups          colo,dost
44        use                     generic-host
45        }
46
47define service{
48        host_name               $name
49        contact_groups          colo
50        use                     ping-service
51        }
52
53define hostescalation{
54        host_name               $name
55        contact_groups          colo,dost-mail
56        first_notification      2
57        last_notification       0
58        notification_interval   0
59        }
60
61define serviceescalation{
62        host_name               $name
63        contact_groups          colo,dost-mail
64        service_description     PING
65        first_notification      2
66        last_notification       0
67        notification_interval   0
68        }
69
70END
71
72    }
73
74    print OUT <<END;
75define hostgroup{
76        hostgroup_name          colo-hosts
77        alias                   colo-hosts
78END
79
80print OUT "\tmembers\t\t\t";
81
82$maybecomma = "";
83foreach $host (@allcolohosts) {
84    print OUT "$maybecomma$host";
85    $maybecomma = ",";
86}
87
88print OUT "\n\t}\n\n";
89
90close(OUT);
91}
92
93$dbh->disconnect;
94
95exit 0;
96
97
Note: See TracBrowser for help on using the repository browser.