]> andersk Git - moira.git/blob - gen/ip-billing.gen
Punt on the "NONE" stuff; the TNS folks decided they liked empty fields more.
[moira.git] / gen / ip-billing.gen
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
9 $ENV{PATH} = "/bin:/usr/bin:/sbin:/usr/sbin";
10
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';
15 $count = 0;
16
17 use DBI;
18
19 umask 022;
20 open(DAT, ">$outdat") || exit $MR_OCONFIG;
21 open(CTL, ">$outctl") || exit $MR_OCONFIG;
22
23 $dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
24   || exit $MR_DBMS_ERR;
25
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") 
32     || exit $MR_DBMS_ERR;
33
34 $sth->execute || exit $MR_DBMS_ERR;
35
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";
39     $row =~ s/\0//g;
40     print DAT $row;
41     $count++;
42 }
43
44 # Next we do the private subnets.
45 # +NETWK-10P.
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")
49     || exit $MR_DBMS_ERR;
50
51 $sth->execute || exit $MR_DBMS_ERR;
52
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";
58     $row =~ s/\0//g;
59     print DAT $row;
60     $count++;
61 }
62
63 # +NETWK-100P
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")
67     || exit $MR_DBMS_ERR;
68
69 $sth->execute || exit $MR_DBMS_ERR;
70
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";
76     $row =~ s/\0//g;
77     print DAT $row;
78     $count++;
79 }
80
81 # +NETWK-1000P
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")
85     || exit $MR_DBMS_ERR;
86
87 $sth->execute || exit $MR_DBMS_ERR;
88
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";
94     $row =~ s/\0//g;
95     print DAT $row;
96     $count++;
97 }
98
99 # +NETWK-0
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;
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-0\t$created\t$modtime\n";
113     $row =~ s/\0//g;
114     print DAT $row;
115     $count++;
116 }
117
118 print CTL "$count\n";
119 close(CTL);
120 close(DAT);
121
122 system("cd $outdir && tar cf $outfile .") == 0 || exit $MR_OCONFIG;
123
124 $dbh->disconnect;
125
126 exit 0;
This page took 0.052295 seconds and 5 git commands to generate.