summaryrefslogtreecommitdiffstats
path: root/scripts/ping.pl
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2018-04-16 10:30:15 +0200
committerSuren A. Chilingaryan <csa@suren.me>2018-04-16 10:30:15 +0200
commit55783753ae8f2d857a7225b7a93c1d47039e5a90 (patch)
treee077b61b0f004141712e7d16876f9c19175ac681 /scripts/ping.pl
downloadconky-55783753ae8f2d857a7225b7a93c1d47039e5a90.tar.gz
conky-55783753ae8f2d857a7225b7a93c1d47039e5a90.tar.bz2
conky-55783753ae8f2d857a7225b7a93c1d47039e5a90.tar.xz
conky-55783753ae8f2d857a7225b7a93c1d47039e5a90.zip
OpenShift monitoring
Diffstat (limited to 'scripts/ping.pl')
-rwxr-xr-xscripts/ping.pl19
1 files changed, 19 insertions, 0 deletions
diff --git a/scripts/ping.pl b/scripts/ping.pl
new file mode 100755
index 0000000..0f24483
--- /dev/null
+++ b/scripts/ping.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/perl -w
+use Net::Ping;
+use Switch;
+
+if (@ARGV >1) { $host=$ARGV[0]; $timeout=$ARGV[1]; }
+elsif (@ARGV>0) { $host=$ARGV[0]; $timeout=2; }
+else { print "Usage is: $0 host <timeout=1>\n"; exit; }
+
+if ($host =~ /^(.*):(\d+)$/) {
+ $host = $1;
+ $port = $2;
+} else {
+ $port = 22;
+}
+
+$p=Net::Ping->new('tcp');
+$p->port_number($port);
+if ($p->ping($host, $timeout)) {print 1;} else {print 0;}
+$p->close();