From 55783753ae8f2d857a7225b7a93c1d47039e5a90 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Mon, 16 Apr 2018 10:30:15 +0200 Subject: OpenShift monitoring --- scripts/conky_process_requests.pl | 77 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 scripts/conky_process_requests.pl (limited to 'scripts/conky_process_requests.pl') diff --git a/scripts/conky_process_requests.pl b/scripts/conky_process_requests.pl new file mode 100755 index 0000000..4e66d7a --- /dev/null +++ b/scripts/conky_process_requests.pl @@ -0,0 +1,77 @@ +#! /usr/bin/perl + +use Digest::MD5 qw(md5_hex); + +$dir = $ENV{'HOME'} . "/.conky/info/"; + +sub process_server_request { + my $server = shift(@_); + my $fn = shift(@_); + + open fl, $fn; + @commands = ; + close fl; + + $n_cmd = 0; + foreach $cmd(@commands) { + if ($cmd !~ /^[\/\w\d_]/) {next;} + $n_cmd = $n_cmd + 1; + } + + if ($n_cmd > 1) { + $ping = $commands[0]; + chomp($ping); + + $md5 = md5_hex($ping); + $res = `$ping`; + + open(fl, ">$dir/$server-$md5.srv"); + print fl $res; + close(fl); + + delete($commands[0]); + } else { + $res = 1 + } + + if ($res > 0) { + foreach $cmd(@commands) { + if ($cmd !~ /^[\/\w\d_]/) {next;} + chomp($cmd); + $md5 = md5_hex($cmd); + open(fl, ">$dir/$server-$md5.srv"); + open(cmd, "$cmd |"); + while () { print fl; } + close(cmd); + close(fl); + } + } +} + +sub process_item { + my $item = shift(@_); + + $fn = $ENV{'HOME'} . "/.conky/requests/" . $item; + if (! -f $fn) { return; } + + if ($item =~ /^(.*)\.srv$/) { + $server = $1; + + process_server_request($server, $fn); + + unlink($fn); + } +} + +opendir dir, $ENV{'HOME'} . "/.conky/requests/"; +@dirlist = readdir dir; +closedir dir; + +if ($#ARGV >= 0) { + $item = shift(@ARGV); + process_item($item); +} else { + foreach $item(@dirlist) { + process_item($item); + } +} -- cgit v1.2.3