use LWP::UserAgent;
use Encode;
use Data::Dumper;
use JSON;
use POSIX;
sub check_es {
my $SDATE = strftime("%Y.%m.%d",localtime());
my $YDATE=strftime("%Y.%m.%d",localtime(time - 86400));
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
$ua->agent("Mozilla/8.0");
#my $host = "http://10.5.100.232:9200/logstash-tlcb-2017.06.10/_search";
my $host1 = "http://10.5.100.232:9200/logstash-tlcb-$SDATE/_search";
my $host2 = "http://10.5.100.232:9200/logstash-tlcb-$YDATE/_search";
my $response = $ua->get($host1);
$ua->default_headers;
if ($response->is_success) {
# print $response->decoded_content; # or whatever
my $r=$response->decoded_content;
my $r=encode_utf8($r);
$hash = decode_json($r);
print $host1."
";
}
else {
my $response = $ua->get($host2);
my $r=$response->decoded_content;
my $r=encode_utf8($r);
$hash = decode_json($r);
print $host2."
";
} ;
return $count= $hash->{'hits'}{total};
};
system(cls);
print "----------------------------------告警监控程序-------------------------------
";
while (1==1){
my $count1=&check_es;
print "init $count1====$count1
";
sleep 1;
my $count2=&check_es;
print "init $count2====$count2
";
if ($count1 == $count2 ){
while(1==1){
my $SDATE = strftime("%Y-%m-%d %H:%M:%S",localtime());
print "$SDATE:$count1====$count1
";
sleep 1;
my $count2=&check_es;
print "$SDATE:$count2====$count2
";
if ($count2 != $count1){
print "warnings are coming";
use Win32::Sound;
Win32::Sound::Volume(65535);
while (<*.wav>) {
Win32::Sound::Play($_);
};
last;
}
};
}else{
use Win32::Sound;
Win32::Sound::Volume(65535);
while (<*.wav>) {
Win32::Sound::Play($_);
};
}
};