diff options
author | Suren A. Chilingaryan <csa@suren.me> | 2018-04-16 10:30:15 +0200 |
---|---|---|
committer | Suren A. Chilingaryan <csa@suren.me> | 2018-04-16 10:30:15 +0200 |
commit | 55783753ae8f2d857a7225b7a93c1d47039e5a90 (patch) | |
tree | e077b61b0f004141712e7d16876f9c19175ac681 /scripts/conky_process_requests.pl | |
download | conky-55783753ae8f2d857a7225b7a93c1d47039e5a90.tar.gz conky-55783753ae8f2d857a7225b7a93c1d47039e5a90.tar.bz2 conky-55783753ae8f2d857a7225b7a93c1d47039e5a90.tar.xz conky-55783753ae8f2d857a7225b7a93c1d47039e5a90.zip |
OpenShift monitoring
Diffstat (limited to 'scripts/conky_process_requests.pl')
-rwxr-xr-x | scripts/conky_process_requests.pl | 77 |
1 files changed, 77 insertions, 0 deletions
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 = <fl>; + 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 (<cmd>) { 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); + } +} |