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

  • 相关阅读:
    [java]Java中父类强制转换成子类的原则
    基于 JWT + Refresh Token 的用户认证实践
    [java]idea设置及debug使用
    [java]Class类和Object类的关系
    [java]文件操作
    [java]javabean
    [java]string类型
    [java]求数据的hmac sha1的并用base64编码
    java 多线程——一个定时调度的例子
    设计模式 4 —— 迭代器和组合模式(组合)
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349684.html
Copyright © 2020-2023  润新知