+#!/moira/bin/perl -Tw
+
+# $Id$
+# The following exit codes are defined and MUST BE CONSISTENT with the
+# error codes the library uses:
+$MR_DBMS_ERR = 47836421;
+$MR_OCONFIG = 47836460;
+
+$outdir = '/moira/dcm/nagios-wsh';
+
+use DBI;
+
+$dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
+ || exit $MR_DBMS_ERR;
+
+$sth0 = $dbh->prepare("SELECT l.list_id, m.name " .
+ "FROM list l, machine m, serverhosts sh " .
+ "WHERE sh.value3 = l.name AND sh.service = " .
+ "'NAGIOS-WSH' AND m.mach_id = sh.mach_id")
+ || exit $MR_DBMS_ERR;
+$sth0->execute;
+
+while (($root_list_id, $hostname) = $sth0->fetchrow_array) {
+ umask 022;
+ open(OUT, ">$outdir/$hostname") || exit $MR_OCONFIG;
+ print OUT "# This file is automatically generated by Moira. Do not edit.\n";
+ $sth = $dbh->prepare("SELECT m.name FROM machine m, imembers i " .
+ "WHERE i.list_id = " . $dbh->quote($root_list_id) .
+ "AND i.member_type = 'MACHINE' AND m.status = 1 " .
+ "AND i.member_id = m.mach_id AND i.direct = 1 ORDER BY m.name")
+ || exit $MR_DBMS_ERR;
+ $sth->execute;
+
+ while (($name) = $sth->fetchrow_array) {
+ next if $name eq "[NONE]";
+ $name = lc($name);
+ push(@allwshhosts, $name);
+ print OUT <<END;
+define host{
+ host_name $name
+ alias $name
+ address $name
+ use generic-host
+ }
+
+define service{
+ host_name $name
+ contact_groups wsh
+ use ping-service
+ }
+
+define hostescalation{
+ host_name $name
+ contact_groups wsh,wsh-mail
+ first_notification 2
+ last_notification 0
+ notification_interval 0
+ }
+
+define serviceescalation{
+ host_name $name
+ contact_groups wsh,wsh-mail
+ service_description PING
+ first_notification 2
+ last_notification 0
+ notification_interval 0
+ }
+
+END
+
+ }
+
+ print OUT <<END;
+define hostgroup{
+ hostgroup_name wsh-hosts
+ alias wsh-hosts
+ contact_groups wsh
+END
+
+print OUT "\tmembers\t\t\t";
+
+$maybecomma = "";
+foreach $host (@allwshhosts) {
+ print OUT "$maybecomma$host";
+ $maybecomma = ",";
+}
+
+print OUT "\n\t}\n\n";
+
+close(OUT);
+}
+
+$dbh->disconnect;
+
+exit 0;
+
+