automatically generate monthly torrus reports before 1st of the month billing, RT...
authorivan <ivan>
Wed, 9 Feb 2011 08:57:23 +0000 (08:57 +0000)
committerivan <ivan>
Wed, 9 Feb 2011 08:57:23 +0000 (08:57 +0000)
FS/FS/Cron/nms_report.pm [new file with mode: 0644]
FS/FS/NetworkMonitoringSystem/Torrus_Internal.pm
FS/bin/freeside-daily

diff --git a/FS/FS/Cron/nms_report.pm b/FS/FS/Cron/nms_report.pm
new file mode 100644 (file)
index 0000000..a34ebe1
--- /dev/null
@@ -0,0 +1,21 @@
+packages FS::Cron::nms_report;
+
+use strict;
+use base 'Exporter';
+use FS::Conf;
+use FS::NetworkMonitoringSystem;
+
+our @EXPORT_OK = qw( nms_report );
+
+sub nms_report {
+  #my %opt = @_;
+
+  my $conf = new FS::Conf;
+  return unless $conf->config('network_monitoring_system');
+
+  my $nms = new FS::NetworkMonitoringSystem;
+  $nms->report; #(%opt);
+
+}
+
+1;
index d55bfc3..e48b6a6 100644 (file)
@@ -94,6 +94,21 @@ sub find_svc {
     return $svc_port[0];
 }
 
+sub report {
+  my $self = shift;
+
+  my @lt = localtime(time);
+  my ($d,$m,$y) = ($ls[3], $ls[4]+1, $ls[5]+1900);
+  if ( $ls[3] == 1 ) {
+    $m--;
+    if ($m == 0) { $m=12; $y-- }
+    #i should have better error checking
+    system('torrus', 'report', '--report=MonthlyUsage', "--date=$y-$m-01");
+    system('torrus', 'report', '--genhtml', '--tree=main');
+  }
+
+}
+
 sub add_router {
   my($self, $ip) = @_;
 
index 09ae132..3e4843b 100755 (executable)
@@ -12,6 +12,10 @@ getopts("p:a:d:vl:sy:nmrkg:u", \%opt);
 my $user = shift or die &usage;
 adminsuidsetup $user;
 
+#you can skip this by not having a NetworkMonitoringSystem configured
+use FS::Cron::nms qw(nms_report);
+nms_report(%opt);
+
 #you can skip this by setting the disable_cron_billing config
 use FS::Cron::bill qw(bill);
 bill(%opt);