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';
20 open(DAT, ">$outdat") || exit $MR_OCONFIG;
21 open(CTL, ">$outctl") || exit $MR_OCONFIG;
23 $dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
26 # First report all the NETWK-A hosts.
27 $sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " .
28 "m.account_number, m.created, m.modtime FROM " .
29 "machine m, subnet s WHERE m.status = 1 " .
30 "AND m.snet_id = s.snet_id AND s.status = 1 " .
31 "AND m.address != 'unassigned' ORDER BY m.address")
34 $sth->execute || exit $MR_DBMS_ERR;
36 while (($address, $location, $name, $contact, $accountnumber, $created, $modtime) =
37 $sth->fetchrow_array) {
38 $row = "$address\t$location\t$name\t$contact\t$accountnumber\t+NETWK-A\t$created\t$modtime\n";
44 # Next we do the private subnets.
46 $sth = $dbh->prepare("SELECT s.saddr, s.name, s.contact, " .
47 "s.account_number, s.modtime FROM subnet s " .
48 "WHERE s.status = 2 ORDER BY s.saddr")
51 $sth->execute || exit $MR_DBMS_ERR;
53 while (($saddr, $name, $contact, $accountnumber, $modtime) =
54 $sth->fetchrow_array) {
55 @addr = unpack("C4", pack("N", $saddr));
56 $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
57 $row = "$address\t\t$name\t$contact\t$accountnumber\t+NETWK-10P\t\t$modtime\n";
64 $sth = $dbh->prepare("SELECT s.saddr, s.name, s.contact, " .
65 "s.account_number, s.modtime FROM subnet s " .
66 "WHERE s.status = 3 ORDER BY s.saddr")
69 $sth->execute || exit $MR_DBMS_ERR;
71 while (($saddr, $name, $contact, $accountnumber, $modtime) =
72 $sth->fetchrow_array) {
73 @addr = unpack("C4", pack("N", $saddr));
74 $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
75 $row = "$address\t\t$name\t$contact\t$accountnumber\t+NETWK-100P\t\t$modtime\n";
82 $sth = $dbh->prepare("SELECT s.saddr, s.name, s.contact, " .
83 "s.account_number, s.modtime FROM subnet s " .
84 "WHERE s.status = 7 ORDER BY s.saddr")
87 $sth->execute || exit $MR_DBMS_ERR;
89 while (($saddr, $name, $contact, $accountnumber, $modtime) =
90 $sth->fetchrow_array) {
91 @addr = unpack("C4", pack("N", $saddr));
92 $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
93 $row = "$address\t\t$name\t$contact\t$accountnumber\t+NETWK-1000P\t\t$modtime\n";
100 $sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " .
101 "m.account_number, m.created, m.modtime FROM " .
102 "machine m, subnet s WHERE m.status = 1 " .
103 "AND m.snet_id = s.snet_id AND " .
104 "(s.status = 4 OR s.status = 5 OR s.status = 6) " .
105 "AND m.address != 'unassigned' ORDER BY m.address")
106 || exit $MR_DBMS_ERR;
108 $sth->execute || exit $MR_DBMS_ERR;
110 while (($address, $location, $name, $contact, $accountnumber, $created, $modtime) =
111 $sth->fetchrow_array) {
112 $row = "$address\t$location\t$name\t$contact\t$accountnumber\t+NETWK-0\t$created\t$modtime\n";
118 print CTL "$count\n";
122 system("cd $outdir && tar cf $outfile .") == 0 || exit $MR_OCONFIG;