<%doc> Add an IP service object from device page % % <%attr> showheader => 0 % <%flags> inherit => undef % % % <%args> $ip $url $service => undef $monitored => undef $contactlist => undef $Add => undef $Cancel => undef % % <%init> my $DEBUG = 0; my $ipobj; my $cl; my $dev; print '%ARGS is
', Dumper(%ARGS), '

' if $DEBUG; if ( $ip ){ unless ( $ipobj = Ipblock->retrieve($ip) ){ $m->comp("error.mhtml", error => "Could not retrieve Ipblock id $ip"); } if ( $ipobj->interface && ( $dev = $ipobj->interface->device ) ){ if ( my @dcs = $dev->contacts ){ # Grab the first one $cl = $dcs[0]->contactlist; } } } my $newsrvid; # Notice the two actions (replace then reload). # This guarantees that we don't reload the page using POST data # when the last request was a POST my $bodyargs; if ( $Add ){ $bodyargs = "onUnload=\"opener.location.replace('$url');opener.location.reload()\""; } else { $bodyargs = ''; } >
Add IP Service
<%perl> if ( $Add ){ my %state; $state{ip} = $ip; $state{service} = $service; if ( IpService->search( %state ) ){ print ("Service already exists
"); }else { $state{monitored} = 1 if ( defined($monitored) && $monitored eq 'on' ); $state{contactlist} = $contactlist if defined $contactlist; eval{ IpService->insert(\%state); }; if ( my $e = $@ ){ $m->comp("error.mhtml", error=>$e); } }
[done] %}elsif ( $Cancel ){
Cancelled.
[done]
%}else{
<%perl> my (@field_headers, @cell_data) = (); push( @field_headers, "IP: " ); push( @cell_data, $ipobj->get_label ); push( @field_headers, "Service: " ); push( @cell_data, &{sub{ my $ac = ''; $ac; }} ); push( @field_headers, "Monitored: " ); push( @cell_data, '' ); push( @field_headers, "Contact List: " ); push( @cell_data, &{sub{ my $ac = ''; $ac; }} ); <& /generic/attribute_table.mhtml, field_headers=>\@field_headers, data=>\@cell_data &>
%} #else