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;
9 $ENV{PATH} = "/bin:/usr/bin:/sbin:/usr/sbin";
11 $outdir = '/moira/dcm/ip-billing';
12 $outfile = '/moira/dcm/ip-billing.out';
13 $outdat = '/moira/dcm/ip-billing/moira.dat';
14 $outctl = '/moira/dcm/ip-billing/moira.ctl';
21 open(DAT, ">$outdat") || exit $MR_OCONFIG;
22 open(CTL, ">$outctl") || exit $MR_OCONFIG;
24 $dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
27 # First report all the NETWK-A hosts.
28 $sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " .
29 "m.account_number, m.modtime FROM " .
30 "machine m, subnet s WHERE m.status = 1 " .
31 "AND m.snet_id = s.snet_id AND s.status = 1 " .
32 "AND m.account_number != CHR(0) ORDER BY m.address")
35 $sth->execute || exit $MR_DBMS_ERR;
37 while (($address, $location, $name, $contact, $accountnumber, $modtime) =
38 $sth->fetchrow_array) {
39 if ($location eq "\0") {
42 if ($contact eq "\0") {
45 $row = "$address\t$location\t$name\t$contact\t$accountnumber\t+NETWK-A\t$modtime\n";
51 # Next we do the private subnets.
53 $sth = $dbh->prepare("SELECT s.saddr, s.description, s.name, s.contact, " .
54 "s.account_number, s.modtime FROM subnet s " .
55 "WHERE s.status = 2 AND s.account_number != CHR(0) " .
59 $sth->execute || exit $MR_DBMS_ERR;
61 while (($saddr, $desc, $name, $contact, $accountnumber, $modtime) =
62 $sth->fetchrow_array) {
66 if ($contact eq "\0") {
69 @addr = unpack("C4", pack("N", $saddr));
70 $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
71 $row = "$address\t$desc\t$name\t$contact\t$accountnumber\t+NETWK-10P\t$modtime\n";
78 $sth = $dbh->prepare("SELECT s.saddr, s.description, s.name, s.contact, " .
79 "s.account_number, s.modtime FROM subnet s " .
80 "WHERE s.status = 3 AND s.account_number != CHR(0) " .
84 $sth->execute || exit $MR_DBMS_ERR;
86 while (($saddr, $desc, $name, $contact, $accountnumber, $modtime) =
87 $sth->fetchrow_array) {
91 if ($contact eq "\0") {
94 @addr = unpack("C4", pack("N", $saddr));
95 $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
96 $row = "$address\t$desc\t$name\t$contact\t$accountnumber\t+NETWK-100P\t$modtime\n";
103 $sth = $dbh->prepare("SELECT s.saddr, s.description, s.name, s.contact, " .
104 "s.account_number, s.modtime FROM subnet s " .
105 "WHERE s.status = 7 AND s.account_number != CHR(0) " .
107 || exit $MR_DBMS_ERR;
109 $sth->execute || exit $MR_DBMS_ERR;
111 while (($saddr, $desc, $name, $contact, $accountnumber, $modtime) =
112 $sth->fetchrow_array) {
116 if ($contact eq "\0") {
119 @addr = unpack("C4", pack("N", $saddr));
120 $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
121 $row = "$address\t$desc\t$name\t$contact\t$accountnumber\t+NETWK-1000P\t$modtime\n";
128 $sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " .
129 "m.account_number, m.modtime FROM " .
130 "machine m, subnet s WHERE m.status = 1 " .
131 "AND m.snet_id = s.snet_id AND " .
132 "(s.status = 4 OR s.status = 5 OR s.status = 6) " .
133 "AND m.account_number != CHR(0) ORDER BY m.address")
134 || exit $MR_DBMS_ERR;
136 $sth->execute || exit $MR_DBMS_ERR;
138 while (($address, $location, $name, $contact, $accountnumber, $modtime) =
139 $sth->fetchrow_array) {
140 if ($location eq "\0") {
143 if ($contact eq "\0") {
146 $row = "$address\t$location\t$name\t$contact\t$accountnumber\t+NETWK-0\t$modtime\n";
152 print CTL "$count\n";
154 system("cd $outdir && tar cf $outfile .") == 0 || exit $MR_OCONFIG;