• perl 轮训检查es条目


    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($_);
              };
     }
    };

  • 相关阅读:
    Linux-进程描述(1)—进程控制块
    C++中的继承(2)类的默认成员
    Linux系统date命令的参数及获取时间戳的方法
    new/new[]和delete/delete[]是如何分配空间以及释放空间的
    golang垃圾回收
    golang内存分配
    go中的关键字-reflect 反射
    go中的关键字-go(下)
    go中的关键字-go(上)
    go中的关键字-defer
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349684.html
Copyright © 2020-2023  润新知