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.created, 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.address != 'unassigned' ORDER BY m.address")
35 $sth->execute || exit $MR_DBMS_ERR;
37 while (($address, $location, $name, $contact, $accountnumber, $created, $modtime) =
38 $sth->fetchrow_array) {
39 if ($location eq "\0") {
42 if ($contact eq "\0") {
45 if ($accountnumber eq "\0") {
46 $accountnumber = "NONE";
48 $row = "$address\t$location\t$name\t$contact\t$accountnumber\t+NETWK-A\t$created\t$modtime\n";
54 # Next we do the private subnets.
56 $sth = $dbh->prepare("SELECT s.saddr, s.name, s.contact, " .
57 "s.account_number, s.modtime FROM subnet s " .
58 "WHERE s.status = 2 ORDER BY s.saddr")
61 $sth->execute || exit $MR_DBMS_ERR;
63 while (($saddr, $name, $contact, $accountnumber, $modtime) =
64 $sth->fetchrow_array) {
65 if ($contact eq "\0") {
68 if ($accountnumber eq "\0") {
69 $accountnumber = "NONE";
71 @addr = unpack("C4", pack("N", $saddr));
72 $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
73 $row = "$address\tNONE\t$name\t$contact\t$accountnumber\t+NETWK-10P\tNONE\t$modtime\n";
80 $sth = $dbh->prepare("SELECT s.saddr, s.name, s.contact, " .
81 "s.account_number, s.modtime FROM subnet s " .
82 "WHERE s.status = 3 ORDER BY s.saddr")
85 $sth->execute || exit $MR_DBMS_ERR;
87 while (($saddr, $name, $contact, $accountnumber, $modtime) =
88 $sth->fetchrow_array) {
89 if ($contact eq "\0") {
92 if ($accountnumber eq "\0") {
93 $accountnumber = "NONE";
95 @addr = unpack("C4", pack("N", $saddr));
96 $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
97 $row = "$address\tNONE\t$name\t$contact\t$accountnumber\t+NETWK-100P\tNONE\t$modtime\n";
104 $sth = $dbh->prepare("SELECT s.saddr, s.name, s.contact, " .
105 "s.account_number, s.modtime FROM subnet s " .
106 "WHERE s.status = 7 ORDER BY s.saddr")
107 || exit $MR_DBMS_ERR;
109 $sth->execute || exit $MR_DBMS_ERR;
111 while (($saddr, $name, $contact, $accountnumber, $modtime) =
112 $sth->fetchrow_array) {
113 if ($contact eq "\0") {
116 if ($accountnumber eq "\0") {
117 $accountnumber = "NONE";
119 @addr = unpack("C4", pack("N", $saddr));
120 $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
121 $row = "$address\tNONE\t$name\t$contact\t$accountnumber\t+NETWK-1000P\tNONE\t$modtime\n";
128 $sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " .
129 "m.account_number, m.created, 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.address != 'unassigned' ORDER BY m.address")
134 || exit $MR_DBMS_ERR;
136 $sth->execute || exit $MR_DBMS_ERR;
138 while (($address, $location, $name, $contact, $accountnumber, $created, $modtime) =
139 $sth->fetchrow_array) {
140 if ($location eq "\0") {
143 if ($contact eq "\0") {
146 if ($accountnumber eq "\0") {
147 $accountnumber = "NONE";
149 $row = "$address\t$location\t$name\t$contact\t$accountnumber\t+NETWK-0\t$created\t$modtime\n";
155 print CTL "$count\n";
159 system("cd $outdir && tar cf $outfile .") == 0 || exit $MR_OCONFIG;