I have OpManager setup to run script monitors on a linux box that checks socket connections to a third (remote server)
The problem is I need to move the current linux system to windows and need to find a way to execute a perl (or other script) on System B from opmanager that checks port/socket status on System C, and get the results back to opmanager.
use strict;
use Socket;
# set time until connection attempt times out
my $timeout = 3;
my $hostname = 'hostname';
my $portnumber = '123';
my $host = shift || $hostname;
my $port = shift || $portnumber;
my $proto = getprotobyname('tcp');
my $iaddr = inet_aton($host);
my $paddr = sockaddr_in($port, $iaddr);
my $Response = 1;
socket(SOCKET, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
eval {
local $SIG{ALRM} = sub { die "timeout" };
alarm($timeout);
connect(SOCKET, $paddr) || error();
alarm(0);
};
if ($@) {
close SOCKET || die "close: $!";
$Response=$Response+11;
print "Message: $hostname not listening on tcp port $portnumber\n";
print "Data:\n";
print "Response\t$Response\n";
exit 9;
}
else {
close SOCKET || die "close: $!";
$Response=$Response-1;
print "Message: $hostname is listening on tcp port $portnumber\n";
print "Data:\n";
print "Response\t$Response";
exit 0;
}