I am writing a heartbeat script to test whether or not our remote systems are up and running. The system consists of a firewall with two public IP's and a server behind the firewall. I need to be able to determine the status of each connection and if the server behind the firewall is responsive.
Since the firewall is set to drop ICMP packets I had to get a little creative with the check. So I used the Net::Ping module to 'ping' the firewall by attempting a connection to the firewall's management website over https. If the connection is refused, the connection is up (vs no reply = down).
I attempted this same thing using http, which should be forwarded through the firewall to the server, but this always came back as alive, even on connections I know are down. Since I also use SNMP to monitor the server, I thought I'd just have try to pull a simple OID from the server. If it works, the server is responsive, if not then it isn't. The problem I'm hitting is that because of a limitation with the firewall, I can't pass udp packets over port 161 through the firewall, so I have to use port 163 then nat them over to 161 on the backside of the firewall. This is all well and good, but I can't seem to get Net::SNMP to use port 163, or if it is, It's just not working. Here is my code:
#!/usr/bin/perl
use warnings;
use strict;
use SNMP;
use Socket;
my $host = 'xxx.xxx.xxx.xxx';
my $oid = '1.3.6.1.2.1.1.4';
my $sver = '1';
my $comm = 'secret';
my $session;
my $reply;
&SNMP::initMib();
my %snmpparms;
$snmpparms{Community} = $comm;
$snmpparms{DestHost} = inet_ntoa(inet_aton($host));
$snmpparms{Version} = $sver;
$snmpparms{UseSprintValue} = '1';
$snmpparms{RemotePort} = '163';
$session = new SNMP::Session(%snmpparms);
$reply = $session->get($oid);
if ($session->{ErrorNum}) {
die "DOOM!: ".$session->{ErrorStr}."\n";
}
print "$reply\n";
running this gives:
DOOM!: Timeout
I know the server is reachable over port 163, as I'm running other monitoring software and I've been able to get this to work in php.
So I guess my question is two-fold. How do I get snmp to work over port 163 and is there a better way to approach this? Possibly make a socket connection with the server over port 80, send some headers and check the reply?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.