]> andersk Git - moira.git/blame - gen/ip-billing.gen
Fix setting of mailroutingaddress.
[moira.git] / gen / ip-billing.gen
CommitLineData
4f6b1a05 1#!/moira/bin/perl -Tw
2
3# $Id$
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;
8
fd59a590 9$ENV{PATH} = "/bin:/usr/bin:/sbin:/usr/sbin";
10
11$outdir = '/moira/dcm/ip-billing';
4f6b1a05 12$outfile = '/moira/dcm/ip-billing.out';
fd59a590 13$outdat = '/moira/dcm/ip-billing/moira.dat';
14$outctl = '/moira/dcm/ip-billing/moira.ctl';
15$count = 0;
4f6b1a05 16
17use DBI;
fd59a590 18
19umask 022;
20open(DAT, ">$outdat") || exit $MR_OCONFIG;
21open(CTL, ">$outctl") || exit $MR_OCONFIG;
4f6b1a05 22
23$dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
24 || exit $MR_DBMS_ERR;
25
fd59a590 26# First report all the NETWK-A hosts.
27$sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " .
d642e8a1 28 "m.billing_contact, m.account_number, m.created, " .
29 "m.modtime FROM machine m, subnet s WHERE m.status = 1 " .
fd59a590 30 "AND m.snet_id = s.snet_id AND s.status = 1 " .
e5efaa67 31 "AND m.address != 'unassigned' ORDER BY m.address")
fd59a590 32 || exit $MR_DBMS_ERR;
4f6b1a05 33
34$sth->execute || exit $MR_DBMS_ERR;
35
d642e8a1 36while (($address, $location, $name, $contact, $billingcontact, $accountnumber, $created, $modtime) =
fd59a590 37 $sth->fetchrow_array) {
d642e8a1 38 $row = "$address\t$location\t$name\t$contact\t$billingcontact\t$accountnumber\t+NETWK-A\t$created\t$modtime\n";
fd59a590 39 $row =~ s/\0//g;
40 print DAT $row;
41 $count++;
42}
43
44# Next we do the private subnets.
45# +NETWK-10P.
e5efaa67 46$sth = $dbh->prepare("SELECT s.saddr, s.name, s.contact, " .
fd59a590 47 "s.account_number, s.modtime FROM subnet s " .
e5efaa67 48 "WHERE s.status = 2 ORDER BY s.saddr")
fd59a590 49 || exit $MR_DBMS_ERR;
50
51$sth->execute || exit $MR_DBMS_ERR;
52
e5efaa67 53while (($saddr, $name, $contact, $accountnumber, $modtime) =
fd59a590 54 $sth->fetchrow_array) {
fd59a590 55 @addr = unpack("C4", pack("N", $saddr));
56 $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
d642e8a1 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";
fd59a590 60 $row =~ s/\0//g;
61 print DAT $row;
62 $count++;
63}
64
65# +NETWK-100P
e5efaa67 66$sth = $dbh->prepare("SELECT s.saddr, s.name, s.contact, " .
fd59a590 67 "s.account_number, s.modtime FROM subnet s " .
e5efaa67 68 "WHERE s.status = 3 ORDER BY s.saddr")
fd59a590 69 || exit $MR_DBMS_ERR;
70
71$sth->execute || exit $MR_DBMS_ERR;
4f6b1a05 72
e5efaa67 73while (($saddr, $name, $contact, $accountnumber, $modtime) =
4f6b1a05 74 $sth->fetchrow_array) {
fd59a590 75 @addr = unpack("C4", pack("N", $saddr));
76 $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
d642e8a1 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";
4f6b1a05 80 $row =~ s/\0//g;
fd59a590 81 print DAT $row;
82 $count++;
4f6b1a05 83}
84
fd59a590 85# +NETWK-1000P
e5efaa67 86$sth = $dbh->prepare("SELECT s.saddr, s.name, s.contact, " .
fd59a590 87 "s.account_number, s.modtime FROM subnet s " .
e5efaa67 88 "WHERE s.status = 7 ORDER BY s.saddr")
fd59a590 89 || exit $MR_DBMS_ERR;
90
91$sth->execute || exit $MR_DBMS_ERR;
92
e5efaa67 93while (($saddr, $name, $contact, $accountnumber, $modtime) =
fd59a590 94 $sth->fetchrow_array) {
fd59a590 95 @addr = unpack("C4", pack("N", $saddr));
96 $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
d642e8a1 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";
fd59a590 100 $row =~ s/\0//g;
101 print DAT $row;
102 $count++;
103}
104
6d928a09 105# +NETWK-DORM
fd59a590 106$sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " .
d642e8a1 107 "m.billing_contact, m.account_number, m.created, " .
108 "m.modtime FROM machine m, subnet s WHERE m.status = 1 " .
fd59a590 109 "AND m.snet_id = s.snet_id AND " .
6d928a09 110 "s.status = 5 AND m.address != 'unassigned' " .
111 "ORDER BY m.address")
112 || exit $MR_DBMS_ERR;
113
114$sth->execute || exit $MR_DBMS_ERR;
115
d642e8a1 116while (($address, $location, $name, $contact, $billingcontact, $accountnumber, $created, $modtime) =
6d928a09 117 $sth->fetchrow_array) {
d642e8a1 118 $row = "$address\t$location\t$name\t$contact\t$billingcontact\t$accountnumber\t+NETWK-DORM\t$created\t$modtime\n";
6d928a09 119 $row =~ s/\0//g;
120 print DAT $row;
121 $count++;
122}
123
124# +NETWK-FSILG
125$sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " .
d642e8a1 126 "m.billing_contact, m.account_number, m.created, " .
127 "m.modtime FROM machine m, subnet s WHERE m.status = 1 " .
6d928a09 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;
132
133$sth->execute || exit $MR_DBMS_ERR;
134
d642e8a1 135while (($address, $location, $name, $contact, $billingcontact, $accountnumber, $created, $modtime) =
6d928a09 136 $sth->fetchrow_array) {
d642e8a1 137 $row = "$address\t$location\t$name\t$contact\t$billingcontact\t$accountnumber\t+NETWK-FSILG\t$created\t$modtime\n";
6d928a09 138 $row =~ s/\0//g;
139 print DAT $row;
140 $count++;
141}
142
143# +NETWK-OCS
144$sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " .
d642e8a1 145 "m.billing_contact, m.account_number, m.created, " .
146 "m.modtime FROM machine m, subnet s WHERE m.status = 1 " .
6d928a09 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;
151
152$sth->execute || exit $MR_DBMS_ERR;
153
d642e8a1 154while (($address, $location, $name, $contact, $billingcontact, $accountnumber, $created, $modtime) =
6d928a09 155 $sth->fetchrow_array) {
d642e8a1 156 $row = "$address\t$location\t$name\t$contact\t$billingcontact\t$accountnumber\t+NETWK-OCS\t$created\t$modtime\n";
6d928a09 157 $row =~ s/\0//g;
158 print DAT $row;
159 $count++;
160}
161
162# +NETWK-0
163$sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " .
d642e8a1 164 "m.billing_contact, m.account_number, m.created, " .
165 "m.modtime FROM machine m, subnet s WHERE m.status = 1 " .
6d928a09 166 "AND m.snet_id = s.snet_id AND " .
167 "(s.status = 4 OR s.status = 6) AND " .
168 "s.name NOT LIKE '%-DHREG' " .
e5efaa67 169 "AND m.address != 'unassigned' ORDER BY m.address")
fd59a590 170 || exit $MR_DBMS_ERR;
171
172$sth->execute || exit $MR_DBMS_ERR;
173
d642e8a1 174while (($address, $location, $name, $contact, $billingcontact, $accountnumber, $created, $modtime) =
fd59a590 175 $sth->fetchrow_array) {
d642e8a1 176 $row = "$address\t$location\t$name\t$contact\t$billingcontact\t$accountnumber\t+NETWK-0\t$created\t$modtime\n";
fd59a590 177 $row =~ s/\0//g;
178 print DAT $row;
179 $count++;
180}
181
182print CTL "$count\n";
e5efaa67 183close(CTL);
184close(DAT);
fd59a590 185
186system("cd $outdir && tar cf $outfile .") == 0 || exit $MR_OCONFIG;
187
4f6b1a05 188$dbh->disconnect;
189
190exit 0;
This page took 0.085903 seconds and 5 git commands to generate.