]>
Commit | Line | Data |
---|---|---|
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 | |
17 | use DBI; | |
fd59a590 | 18 | |
19 | umask 022; | |
20 | open(DAT, ">$outdat") || exit $MR_OCONFIG; | |
21 | open(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, " . | |
e5efaa67 | 28 | "m.account_number, m.created, m.modtime FROM " . |
fd59a590 | 29 | "machine m, subnet s WHERE m.status = 1 " . |
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 | ||
e5efaa67 | 36 | while (($address, $location, $name, $contact, $accountnumber, $created, $modtime) = |
fd59a590 | 37 | $sth->fetchrow_array) { |
e5efaa67 | 38 | $row = "$address\t$location\t$name\t$contact\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 | 53 | while (($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]"; | |
f0656ce3 | 57 | $row = "$address\t\t$name\t$contact\t$accountnumber\t+NETWK-10P\t\t$modtime\n"; |
fd59a590 | 58 | $row =~ s/\0//g; |
59 | print DAT $row; | |
60 | $count++; | |
61 | } | |
62 | ||
63 | # +NETWK-100P | |
e5efaa67 | 64 | $sth = $dbh->prepare("SELECT s.saddr, s.name, s.contact, " . |
fd59a590 | 65 | "s.account_number, s.modtime FROM subnet s " . |
e5efaa67 | 66 | "WHERE s.status = 3 ORDER BY s.saddr") |
fd59a590 | 67 | || exit $MR_DBMS_ERR; |
68 | ||
69 | $sth->execute || exit $MR_DBMS_ERR; | |
4f6b1a05 | 70 | |
e5efaa67 | 71 | while (($saddr, $name, $contact, $accountnumber, $modtime) = |
4f6b1a05 | 72 | $sth->fetchrow_array) { |
fd59a590 | 73 | @addr = unpack("C4", pack("N", $saddr)); |
74 | $address = "$addr[0].$addr[1].$addr[2].$addr[3]"; | |
f0656ce3 | 75 | $row = "$address\t\t$name\t$contact\t$accountnumber\t+NETWK-100P\t\t$modtime\n"; |
4f6b1a05 | 76 | $row =~ s/\0//g; |
fd59a590 | 77 | print DAT $row; |
78 | $count++; | |
4f6b1a05 | 79 | } |
80 | ||
fd59a590 | 81 | # +NETWK-1000P |
e5efaa67 | 82 | $sth = $dbh->prepare("SELECT s.saddr, s.name, s.contact, " . |
fd59a590 | 83 | "s.account_number, s.modtime FROM subnet s " . |
e5efaa67 | 84 | "WHERE s.status = 7 ORDER BY s.saddr") |
fd59a590 | 85 | || exit $MR_DBMS_ERR; |
86 | ||
87 | $sth->execute || exit $MR_DBMS_ERR; | |
88 | ||
e5efaa67 | 89 | while (($saddr, $name, $contact, $accountnumber, $modtime) = |
fd59a590 | 90 | $sth->fetchrow_array) { |
fd59a590 | 91 | @addr = unpack("C4", pack("N", $saddr)); |
92 | $address = "$addr[0].$addr[1].$addr[2].$addr[3]"; | |
f0656ce3 | 93 | $row = "$address\t\t$name\t$contact\t$accountnumber\t+NETWK-1000P\t\t$modtime\n"; |
fd59a590 | 94 | $row =~ s/\0//g; |
95 | print DAT $row; | |
96 | $count++; | |
97 | } | |
98 | ||
6d928a09 | 99 | # +NETWK-DORM |
fd59a590 | 100 | $sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " . |
e5efaa67 | 101 | "m.account_number, m.created, m.modtime FROM " . |
fd59a590 | 102 | "machine m, subnet s WHERE m.status = 1 " . |
103 | "AND m.snet_id = s.snet_id AND " . | |
6d928a09 | 104 | "s.status = 5 AND m.address != 'unassigned' " . |
105 | "ORDER BY m.address") | |
106 | || exit $MR_DBMS_ERR; | |
107 | ||
108 | $sth->execute || exit $MR_DBMS_ERR; | |
109 | ||
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-DORM\t$created\t$modtime\n"; | |
113 | $row =~ s/\0//g; | |
114 | print DAT $row; | |
115 | $count++; | |
116 | } | |
117 | ||
118 | # +NETWK-FSILG | |
119 | $sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " . | |
120 | "m.account_number, m.created, m.modtime FROM " . | |
121 | "machine m, subnet s WHERE m.status = 1 " . | |
122 | "AND m.snet_id = s.snet_id AND " . | |
123 | "s.status = 8 AND m.address != 'unassigned' " . | |
124 | "ORDER BY m.address") | |
125 | || exit $MR_DBMS_ERR; | |
126 | ||
127 | $sth->execute || exit $MR_DBMS_ERR; | |
128 | ||
129 | while (($address, $location, $name, $contact, $accountnumber, $created, $modtime) = | |
130 | $sth->fetchrow_array) { | |
131 | $row = "$address\t$location\t$name\t$contact\t$accountnumber\t+NETWK-FSILG\t$created\t$modtime\n"; | |
132 | $row =~ s/\0//g; | |
133 | print DAT $row; | |
134 | $count++; | |
135 | } | |
136 | ||
137 | # +NETWK-OCS | |
138 | $sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " . | |
139 | "m.account_number, m.created, m.modtime FROM " . | |
140 | "machine m, subnet s WHERE m.status = 1 " . | |
141 | "AND m.snet_id = s.snet_id AND " . | |
142 | "s.status = 6 AND s.name LIKE '%-DHREG' " . | |
143 | "AND m.address != 'unassigned' ORDER BY m.address") | |
144 | || exit $MR_DBMS_ERR; | |
145 | ||
146 | $sth->execute || exit $MR_DBMS_ERR; | |
147 | ||
148 | while (($address, $location, $name, $contact, $accountnumber, $created, $modtime) = | |
149 | $sth->fetchrow_array) { | |
150 | $row = "$address\t$location\t$name\t$contact\t$accountnumber\t+NETWK-OCS\t$created\t$modtime\n"; | |
151 | $row =~ s/\0//g; | |
152 | print DAT $row; | |
153 | $count++; | |
154 | } | |
155 | ||
156 | # +NETWK-0 | |
157 | $sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " . | |
158 | "m.account_number, m.created, m.modtime FROM " . | |
159 | "machine m, subnet s WHERE m.status = 1 " . | |
160 | "AND m.snet_id = s.snet_id AND " . | |
161 | "(s.status = 4 OR s.status = 6) AND " . | |
162 | "s.name NOT LIKE '%-DHREG' " . | |
e5efaa67 | 163 | "AND m.address != 'unassigned' ORDER BY m.address") |
fd59a590 | 164 | || exit $MR_DBMS_ERR; |
165 | ||
166 | $sth->execute || exit $MR_DBMS_ERR; | |
167 | ||
e5efaa67 | 168 | while (($address, $location, $name, $contact, $accountnumber, $created, $modtime) = |
fd59a590 | 169 | $sth->fetchrow_array) { |
e5efaa67 | 170 | $row = "$address\t$location\t$name\t$contact\t$accountnumber\t+NETWK-0\t$created\t$modtime\n"; |
fd59a590 | 171 | $row =~ s/\0//g; |
172 | print DAT $row; | |
173 | $count++; | |
174 | } | |
175 | ||
176 | print CTL "$count\n"; | |
e5efaa67 | 177 | close(CTL); |
178 | close(DAT); | |
fd59a590 | 179 | |
180 | system("cd $outdir && tar cf $outfile .") == 0 || exit $MR_OCONFIG; | |
181 | ||
4f6b1a05 | 182 | $dbh->disconnect; |
183 | ||
184 | exit 0; |