use Fcntl qw(:flock);
use IO::File;
use File::Slurp qw(slurp);
+use Date::Format;
#$DEBUG = 0;
#$me = '[FS::NetworkMonitoringSystem::Torrus_Internal]';
our $lockfile = '/usr/local/etc/torrus/discovery/FSLOCK';
our $ddxfile = '/usr/local/etc/torrus/discovery/routers.ddx';
+sub new {
+ my $class = shift;
+ my $self = {};
+ bless $self, $class;
+ return $self;
+}
+
sub add_router {
my($self, $ip) = @_;
next unless $line =~ /^\s*<param\s+name="snmp-host"\s+value="$router_ip"\/?>/i;
while ( my $hostline = shift(@ddx) ) {
- $new .= "$hostline\n";
+ $new .= "$hostline\n" unless $hostline =~ /^\s+<\/host>\s*/i;
if ( $hostline =~ /^\s*<param name="RFC2863_IF_MIB::external-serviceid"\/?>/i ) {
while ( my $paramline = shift(@ddx) ) {
- if ( $paramline =~ /^\s*</param>/ ) {
+ if ( $paramline =~ /^\s*<\/param>/ ) {
$new .= "$newline\n$paramline";
last; #paramline
} else {
$new .=
qq( <param name="RFC2863_IF_MIB::external-serviceid">\n).
qq( $newline\n").
- qq( </param>\n).
+ qq( </param>\n);
}
$new .= $hostline;
last; #hostline
}
sub _torrus_lock {
- $lock = new IO:::File ">>$lockfile" or die $!;
+ $lock = new IO::File ">>$lockfile" or die $!;
flock($lock, LOCK_EX);
}
or die "can't write to $ddxfile.new: $!";
print $new $ddx;
close $new;
- rename("$ddxfile", $ddxfile.`date +%Y%m%d%H%M%S`) or die $!;
+
+ # `date ...` created file names with weird chars in them
+ my $tmpname = $ddxfile . Date::Format::time2str('%Y%m%d%H%M%S',time);
+ rename("$ddxfile", $tmpname) or die $!;
rename("$ddxfile.new", $ddxfile) or die $!;
$self->_torrus_reload;
<BR>
<FORM NAME="nms-add_iface" ACTION="<% popurl(1) %>process/nms-add_iface.html" METHOD=POST>
+<INPUT TYPE="HIDDEN" name="iface" value="<%$iface%>">
+<INPUT TYPE="HIDDEN" name="host" value="<%$host%>">
Torrus Service Id
<% include('/elements/input-text.html',
'field' => 'serviceid',
--- /dev/null
+<% header('Interface added') %>
+</BODY></HTML>
+<%init>
+
+# XXX: access rights
+
+my $host = $cgi->param('host');
+die 'invalid host' unless $host =~ /^[0-9.a-zA-Z\-]+$/;
+
+my $iface = $cgi->param('iface');
+die 'invalid iface' unless $iface =~ /^[0-9A-Za-z_\-.\\\/ ]+$/;
+
+my $serviceid = $cgi->param('serviceid');
+die 'invalid serviceid' unless $serviceid =~ /^[0-9A-Za-z_\-.\\\/ ]+$/;
+
+my $conf = new FS::Conf;
+my $system = $conf->config('network_monitoring_system');
+
+my $nms = new FS::NetworkMonitoringSystem;
+$nms->add_interface($host,$iface,$serviceid);
+
+</%init>