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.billing_contact, m.account_number, m.created, " .
29 "m.modtime FROM 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, $billingcontact, $accountnumber, $created, $modtime) =
37 $sth->fetchrow_array) {
38 $row = "$address\t$location\t$name\t$contact\t$billingcontact\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 # Blank field between contact and account number below because that's
58 # where the billing contact would go if we had it for subnets.
59 $row = "$address\t\t$name\t$contact\t\t$accountnumber\t+NETWK-10P\t\t$modtime\n";
66 $sth = $dbh->prepare("SELECT s.saddr, s.name, s.contact, " .
67 "s.account_number, s.modtime FROM subnet s " .
68 "WHERE s.status = 3 ORDER BY s.saddr")
71 $sth->execute || exit $MR_DBMS_ERR;
73 while (($saddr, $name, $contact, $accountnumber, $modtime) =
74 $sth->fetchrow_array) {
75 @addr = unpack("C4", pack("N", $saddr));
76 $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
77 # Blank field between contact and account number below because that's
78 # where the billing contact would go if we had it for subnets.
79 $row = "$address\t\t$name\t$contact\t\t$accountnumber\t+NETWK-100P\t\t$modtime\n";
86 $sth = $dbh->prepare("SELECT s.saddr, s.name, s.contact, " .
87 "s.account_number, s.modtime FROM subnet s " .
88 "WHERE s.status = 7 ORDER BY s.saddr")
91 $sth->execute || exit $MR_DBMS_ERR;
93 while (($saddr, $name, $contact, $accountnumber, $modtime) =
94 $sth->fetchrow_array) {
95 @addr = unpack("C4", pack("N", $saddr));
96 $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
97 # Blank field between contact and account number below because that's
98 # where the billing contact would go if we had it for subnets.
99 $row = "$address\t\t$name\t$contact\t\t$accountnumber\t+NETWK-1000P\t\t$modtime\n";
106 $sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " .
107 "m.billing_contact, m.account_number, m.created, " .
108 "m.modtime FROM machine m, subnet s WHERE m.status = 1 " .
109 "AND m.snet_id = s.snet_id AND " .
110 "s.status = 5 AND m.address != 'unassigned' " .
111 "ORDER BY m.address")
112 || exit $MR_DBMS_ERR;
114 $sth->execute || exit $MR_DBMS_ERR;
116 while (($address, $location, $name, $contact, $billingcontact, $accountnumber, $created, $modtime) =
117 $sth->fetchrow_array) {
118 $row = "$address\t$location\t$name\t$contact\t$billingcontact\t$accountnumber\t+NETWK-DORM\t$created\t$modtime\n";
125 $sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " .
126 "m.billing_contact, m.account_number, m.created, " .
127 "m.modtime FROM machine m, subnet s WHERE m.status = 1 " .
128 "AND m.snet_id = s.snet_id AND " .
129 "s.status = 8 AND m.address != 'unassigned' " .
130 "ORDER BY m.address")
131 || exit $MR_DBMS_ERR;
133 $sth->execute || exit $MR_DBMS_ERR;
135 while (($address, $location, $name, $contact, $billingcontact, $accountnumber, $created, $modtime) =
136 $sth->fetchrow_array) {
137 $row = "$address\t$location\t$name\t$contact\t$billingcontact\t$accountnumber\t+NETWK-FSILG\t$created\t$modtime\n";
144 $sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " .
145 "m.billing_contact, m.account_number, m.created, " .
146 "m.modtime FROM machine m, subnet s WHERE m.status = 1 " .
147 "AND m.snet_id = s.snet_id AND " .
148 "s.status = 6 AND s.name LIKE '%-DHREG' " .
149 "AND m.address != 'unassigned' ORDER BY m.address")
150 || exit $MR_DBMS_ERR;
152 $sth->execute || exit $MR_DBMS_ERR;
154 while (($address, $location, $name, $contact, $billingcontact, $accountnumber, $created, $modtime) =
155 $sth->fetchrow_array) {
156 $row = "$address\t$location\t$name\t$contact\t$billingcontact\t$accountnumber\t+NETWK-OCS\t$created\t$modtime\n";
163 $sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " .
164 "m.billing_contact, m.account_number, m.created, " .
165 "m.modtime FROM machine m, subnet s WHERE m.status = 1 " .
166 "AND m.snet_id = s.snet_id AND " .
167 "(s.status = 4 OR s.status = 6) AND " .
168 "s.name NOT LIKE '%-DHREG' " .
169 "AND m.address != 'unassigned' ORDER BY m.address")
170 || exit $MR_DBMS_ERR;
172 $sth->execute || exit $MR_DBMS_ERR;
174 while (($address, $location, $name, $contact, $billingcontact, $accountnumber, $created, $modtime) =
175 $sth->fetchrow_array) {
176 $row = "$address\t$location\t$name\t$contact\t$billingcontact\t$accountnumber\t+NETWK-0\t$created\t$modtime\n";
182 print CTL "$count\n";
186 system("cd $outdir && tar cf $outfile .") == 0 || exit $MR_OCONFIG;