]> andersk Git - moira.git/blob - gen/ip-billing.gen
94972303f2e066dce971ac5594ed0de53c26da9d
[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 use Socket;
19
20 umask 022;
21 open(DAT, ">$outdat") || exit $MR_OCONFIG;
22 open(CTL, ">$outctl") || exit $MR_OCONFIG;
23
24 $dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
25   || exit $MR_DBMS_ERR;
26
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.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.account_number != CHR(0) ORDER BY m.address") 
33     || exit $MR_DBMS_ERR;
34
35 $sth->execute || exit $MR_DBMS_ERR;
36
37 while (($address, $location, $name, $contact, $accountnumber, $modtime) =
38        $sth->fetchrow_array) {
39     if ($location eq "\0") {
40         $location = "NONE";
41     }
42     if ($contact eq "\0") {
43         $contact = "NONE";
44     }
45     $row = "$address\t$location\t$name\t$contact\t$accountnumber\t+NETWK-A\t$modtime\n";
46     $row =~ s/\0//g;
47     print DAT $row;
48     $count++;
49 }
50
51 # Next we do the private subnets.
52 # +NETWK-10P.
53 $sth = $dbh->prepare("SELECT s.saddr, s.description, s.name, s.contact, " .
54                      "s.account_number, s.modtime FROM subnet s " .
55                      "WHERE s.status = 2 AND s.account_number != CHR(0) " .
56                      "ORDER BY s.saddr")
57     || exit $MR_DBMS_ERR;
58
59 $sth->execute || exit $MR_DBMS_ERR;
60
61 while (($saddr, $desc, $name, $contact, $accountnumber, $modtime) =
62        $sth->fetchrow_array) {
63     if ($desc eq "\0") {
64         $desc = "NONE";
65     }
66     if ($contact eq "\0") {
67         $contact = "NONE";
68     }
69     @addr = unpack("C4", pack("N", $saddr));
70     $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
71     $row = "$address\t$desc\t$name\t$contact\t$accountnumber\t+NETWK-10P\t$modtime\n";
72     $row =~ s/\0//g;
73     print DAT $row;
74     $count++;
75 }
76
77 # +NETWK-100P
78 $sth = $dbh->prepare("SELECT s.saddr, s.description, s.name, s.contact, " .
79                      "s.account_number, s.modtime FROM subnet s " .
80                      "WHERE s.status = 3 AND s.account_number != CHR(0) " .
81                      "ORDER BY s.saddr")
82     || exit $MR_DBMS_ERR;
83
84 $sth->execute || exit $MR_DBMS_ERR;
85
86 while (($saddr, $desc, $name, $contact, $accountnumber, $modtime) =
87        $sth->fetchrow_array) {
88     if ($desc eq "\0") {
89         $desc = "NONE";
90     }
91     if ($contact eq "\0") {
92         $contact = "NONE";
93     }
94     @addr = unpack("C4", pack("N", $saddr));
95     $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
96     $row = "$address\t$desc\t$name\t$contact\t$accountnumber\t+NETWK-100P\t$modtime\n";
97     $row =~ s/\0//g;
98     print DAT $row;
99     $count++;
100 }
101
102 # +NETWK-1000P
103 $sth = $dbh->prepare("SELECT s.saddr, s.description, s.name, s.contact, " .
104                      "s.account_number, s.modtime FROM subnet s " .
105                      "WHERE s.status = 7 AND s.account_number != CHR(0) " .
106                      "ORDER BY s.saddr")
107     || exit $MR_DBMS_ERR;
108
109 $sth->execute || exit $MR_DBMS_ERR;
110
111 while (($saddr, $desc, $name, $contact, $accountnumber, $modtime) =
112        $sth->fetchrow_array) {
113     if ($desc eq "\0") {
114         $desc = "NONE";
115     }
116     if ($contact eq "\0") {
117         $contact = "NONE";
118     }
119     @addr = unpack("C4", pack("N", $saddr));
120     $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
121     $row = "$address\t$desc\t$name\t$contact\t$accountnumber\t+NETWK-1000P\t$modtime\n";
122     $row =~ s/\0//g;
123     print DAT $row;
124     $count++;
125 }
126
127 # +NETWK-0
128 $sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " .
129                      "m.account_number, 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.account_number != CHR(0) ORDER BY m.address") 
134     || exit $MR_DBMS_ERR;
135
136 $sth->execute || exit $MR_DBMS_ERR;
137
138 while (($address, $location, $name, $contact, $accountnumber, $modtime) =
139        $sth->fetchrow_array) {
140     if ($location eq "\0") {
141         $location = "NONE";
142     }
143     if ($contact eq "\0") {
144         $contact = "NONE";
145     }
146     $row = "$address\t$location\t$name\t$contact\t$accountnumber\t+NETWK-0\t$modtime\n";
147     $row =~ s/\0//g;
148     print DAT $row;
149     $count++;
150 }
151
152 print CTL "$count\n";
153
154 system("cd $outdir && tar cf $outfile .") == 0 || exit $MR_OCONFIG;
155
156 close(DAT);
157 close(CTL);
158 $dbh->disconnect;
159
160 exit 0;
This page took 0.037734 seconds and 3 git commands to generate.