]> andersk Git - moira.git/commitdiff
Include private subnets and hosts on unbilled networks in feed to
authorzacheiss <zacheiss>
Mon, 4 Feb 2002 05:21:34 +0000 (05:21 +0000)
committerzacheiss <zacheiss>
Mon, 4 Feb 2002 05:21:34 +0000 (05:21 +0000)
IP billing system.  Add a script to unpack the tar file, and Makefile.in
changes to install the DCM programs.

gen/Makefile.in
gen/ip-billing.gen
gen/ip-billing.sh [new file with mode: 0755]

index 1c8f086889c56b7d6affb56cb7bc2071502ca8d6..446703ec2c918cad4c4f9c1ada08bb6cd0deb088 100644 (file)
@@ -42,10 +42,11 @@ TARGET=     acl.gen boot.gen dhcp.gen directory.gen hesiod.gen hosts.gen \
        mailhub.gen ndb.gen network.gen nfs.gen pobox.gen \
        postoffice.gen print.gen warehouse.gen winad.gen www.gen zephyr.gen
 
-SCRIPTS=boot.sh ca.gen dhcp.sh hesiod.sh ip-billing.gen longjobs.gen \
-       longjobs.sh mailhub.sh ndb.sh nfs.sh null.sh postoffice.sh print.sh \
-       sapprint.gen sapprint.sh spwatch.gen stellar.gen stellar.sh \
-       warehouse.sh www.sh zephyr.sh install_dirs install_quotas zero_quotas
+SCRIPTS=boot.sh ca.gen dhcp.sh hesiod.sh ip-billing.gen ip-billing.sh \
+       longjobs.gen longjobs.sh mailhub.sh ndb.sh nfs.sh null.sh \
+       postoffice.sh print.sh sapprint.gen sapprint.sh spwatch.gen \
+       stellar.gen stellar.sh warehouse.sh www.sh zephyr.sh \
+       install_dirs install_quotas zero_quotas
 
 .SUFFIXES: .pc .gen
 
index b7b22e90f7b37eb03b29bdf3efd28b38e0cf96e2..94972303f2e066dce971ac5594ed0de53c26da9d 100755 (executable)
 $MR_DBMS_ERR = 47836421;
 $MR_OCONFIG = 47836460;
 
+$ENV{PATH} = "/bin:/usr/bin:/sbin:/usr/sbin";
+
+$outdir = '/moira/dcm/ip-billing';
 $outfile = '/moira/dcm/ip-billing.out';
+$outdat = '/moira/dcm/ip-billing/moira.dat';
+$outctl = '/moira/dcm/ip-billing/moira.ctl';
+$count = 0;
 
 use DBI;
+use Socket;
+
+umask 022;
+open(DAT, ">$outdat") || exit $MR_OCONFIG;
+open(CTL, ">$outctl") || exit $MR_OCONFIG;
 
 $dbh = DBI->connect("dbi:Oracle:moira", "moira", "moira")
   || exit $MR_DBMS_ERR;
 
-$sth = $dbh->prepare("SELECT m.address, m.location, m.account_number, " .
-                    "m.name, m.contact FROM machine m, subnet s WHERE " .
-                    "m.status = 1 and m.snet_id = s.snet_id " .
-                    "AND s.status = 1") || exit $MR_DBMS_ERR;
+# First report all the NETWK-A hosts.
+$sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " .
+                    "m.account_number, m.modtime FROM " .
+                    "machine m, subnet s WHERE m.status = 1 " .
+                    "AND m.snet_id = s.snet_id AND s.status = 1 " .
+                    "AND m.account_number != CHR(0) ORDER BY m.address") 
+    || exit $MR_DBMS_ERR;
 
 $sth->execute || exit $MR_DBMS_ERR;
 
-umask 022;
-open(OUT, ">$outfile") || exit $MR_OCONFIG;
+while (($address, $location, $name, $contact, $accountnumber, $modtime) =
+       $sth->fetchrow_array) {
+    if ($location eq "\0") {
+       $location = "NONE";
+    }
+    if ($contact eq "\0") {
+       $contact = "NONE";
+    }
+    $row = "$address\t$location\t$name\t$contact\t$accountnumber\t+NETWK-A\t$modtime\n";
+    $row =~ s/\0//g;
+    print DAT $row;
+    $count++;
+}
+
+# Next we do the private subnets.
+# +NETWK-10P.
+$sth = $dbh->prepare("SELECT s.saddr, s.description, s.name, s.contact, " .
+                    "s.account_number, s.modtime FROM subnet s " .
+                    "WHERE s.status = 2 AND s.account_number != CHR(0) " .
+                    "ORDER BY s.saddr")
+    || exit $MR_DBMS_ERR;
+
+$sth->execute || exit $MR_DBMS_ERR;
+
+while (($saddr, $desc, $name, $contact, $accountnumber, $modtime) =
+       $sth->fetchrow_array) {
+    if ($desc eq "\0") {
+       $desc = "NONE";
+    }
+    if ($contact eq "\0") {
+       $contact = "NONE";
+    }
+    @addr = unpack("C4", pack("N", $saddr));
+    $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
+    $row = "$address\t$desc\t$name\t$contact\t$accountnumber\t+NETWK-10P\t$modtime\n";
+    $row =~ s/\0//g;
+    print DAT $row;
+    $count++;
+}
+
+# +NETWK-100P
+$sth = $dbh->prepare("SELECT s.saddr, s.description, s.name, s.contact, " .
+                    "s.account_number, s.modtime FROM subnet s " .
+                    "WHERE s.status = 3 AND s.account_number != CHR(0) " .
+                    "ORDER BY s.saddr")
+    || exit $MR_DBMS_ERR;
+
+$sth->execute || exit $MR_DBMS_ERR;
 
-while (($address, $location, $accountnumber, $hostname, $contact) =
+while (($saddr, $desc, $name, $contact, $accountnumber, $modtime) =
        $sth->fetchrow_array) {
-    $row= "$address\t$location\t$accountnumber\t$hostname\t$contact\n";
+    if ($desc eq "\0") {
+       $desc = "NONE";
+    }
+    if ($contact eq "\0") {
+       $contact = "NONE";
+    }
+    @addr = unpack("C4", pack("N", $saddr));
+    $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
+    $row = "$address\t$desc\t$name\t$contact\t$accountnumber\t+NETWK-100P\t$modtime\n";
     $row =~ s/\0//g;
-    print OUT $row;
+    print DAT $row;
+    $count++;
 }
 
-close(OUT);
+# +NETWK-1000P
+$sth = $dbh->prepare("SELECT s.saddr, s.description, s.name, s.contact, " .
+                    "s.account_number, s.modtime FROM subnet s " .
+                    "WHERE s.status = 7 AND s.account_number != CHR(0) " .
+                    "ORDER BY s.saddr")
+    || exit $MR_DBMS_ERR;
+
+$sth->execute || exit $MR_DBMS_ERR;
+
+while (($saddr, $desc, $name, $contact, $accountnumber, $modtime) =
+       $sth->fetchrow_array) {
+    if ($desc eq "\0") {
+       $desc = "NONE";
+    }
+    if ($contact eq "\0") {
+       $contact = "NONE";
+    }
+    @addr = unpack("C4", pack("N", $saddr));
+    $address = "$addr[0].$addr[1].$addr[2].$addr[3]";
+    $row = "$address\t$desc\t$name\t$contact\t$accountnumber\t+NETWK-1000P\t$modtime\n";
+    $row =~ s/\0//g;
+    print DAT $row;
+    $count++;
+}
+
+# +NETWK-0
+$sth = $dbh->prepare("SELECT m.address, m.location, m.name, m.contact, " .
+                    "m.account_number, m.modtime FROM " .
+                    "machine m, subnet s WHERE m.status = 1 " .
+                    "AND m.snet_id = s.snet_id AND " .
+                    "(s.status = 4 OR s.status = 5 OR s.status = 6) " .
+                    "AND m.account_number != CHR(0) ORDER BY m.address") 
+    || exit $MR_DBMS_ERR;
+
+$sth->execute || exit $MR_DBMS_ERR;
+
+while (($address, $location, $name, $contact, $accountnumber, $modtime) =
+       $sth->fetchrow_array) {
+    if ($location eq "\0") {
+       $location = "NONE";
+    }
+    if ($contact eq "\0") {
+       $contact = "NONE";
+    }
+    $row = "$address\t$location\t$name\t$contact\t$accountnumber\t+NETWK-0\t$modtime\n";
+    $row =~ s/\0//g;
+    print DAT $row;
+    $count++;
+}
+
+print CTL "$count\n";
+
+system("cd $outdir && tar cf $outfile .") == 0 || exit $MR_OCONFIG;
+
+close(DAT);
+close(CTL);
 $dbh->disconnect;
 
 exit 0;
diff --git a/gen/ip-billing.sh b/gen/ip-billing.sh
new file mode 100755 (executable)
index 0000000..afba3bb
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/sh
+# 
+# $Header: /afs/athena.mit.edu/astaff/project/moiradev/repository/moira/gen/stel
+lar.sh,v 1.1 2002/01/18 06:54:45 zacheiss Exp $
+
+PATH=/usr/bin:/bin:/usr/sbin:/sbin
+
+if [ -d /var/athena ] && [ -w /var/athena ]; then
+    exec >/var/athena/moira_update.log 2>&1
+else 
+    exec >/tmp/moira_update.log 2>&1
+fi
+
+# The following exit codes are defined and MUST BE CONSISTENT with the 
+# error codes the library uses:
+MR_MISSINGFILE=47836473
+MR_TARERR=47836476
+
+OUTFILE=/var/tmp/ip-billing.out
+
+# Alert if the output file doesn't exist
+test -r $OUTFILE || exit $MR_MISSINGFILE
+
+# unpack the file
+(cd /var/tmp && tar xf $OUTFILE) || exit $MR_TARERR
+
+# cleanup
+rm -f $OUTFILE
+test -f $0 && rm -f $0
+
+exit 0
This page took 0.053115 seconds and 5 git commands to generate.