nagios插件之检测mqa的日志文件更新时间
来源:互联网 发布:美工简历自我介绍 编辑:程序博客网 时间:2024/05/21 18:37
vi check_file_uptime.c
#include <stdio.h>#include <stdlib.h>#include <time.h>#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>#include <errno.h>#include <ifaddrs.h>#include <netinet/in.h> #include <arpa/inet.h>#include <string.h> #define OK 0#define WARNING 1#define CRITICAL 2#define UNKNOWN 3#define LEN 1023//#define LOG_FILE "/var/log/asterisk/cdr-csv/Master.csv"////#define LOG_FILE "/DATE/anylink/probus5/logs/SPZHJJR1/SPZHJJR1_RTEcontainer1/servlet/accesslog/access.log"//#define LOG_FILE "/DATE/anylink/probus5/logs/SPZHJJR4/SPZHJJR4_RTEcontainer1/servlet/accesslog/access.log"#define LOG_FILE "/opt/MQ-Adapter/log/mqsgip.log"//#define LOG_FILE "/home/uniadmin/neo/test/check_file_time/Master.csv"#define SHORT_TIME 300#define LONG_TIME 1200//#define TIME 60int exitstatus=OK;char *exit_status[4]={"OK","WARNING","CRITICAL","UNKNOWN"};char status_information[LEN];char performance_data[LEN];time_t timestamp;int is_master_or_slave(void) { int mark=0; struct ifaddrs * ifAddrStruct=NULL; void * tmpAddrPtr=NULL; char addressBuffer[INET_ADDRSTRLEN]; getifaddrs(&ifAddrStruct); while(ifAddrStruct!=NULL) { tmpAddrPtr=&((struct sockaddr_in *)ifAddrStruct->ifa_addr)->sin_addr; inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN); // if (ifAddrStruct->ifa_addr->sa_family==AF_INET) { // if (!strncmp(addressBuffer,"10.199.75.169",13)) { if (!strcmp(addressBuffer,"10.127.2.137")) { // printf("%s IP Address %s\n", ifAddrStruct->ifa_name, addressBuffer); mark=1; break; } ifAddrStruct=ifAddrStruct->ifa_next; } if(mark==1) { return 1; } else return 0;}int diff_time(int istime) { int ret; int result=0; struct stat getstat;// printf("istime=%d\n",istime);// timestamp=time(NULL);// printf("now time=%d\n",timestamp); ret=stat(LOG_FILE,&getstat); if(ret==-1) { if(errno==ENOENT) { fprintf(stderr,"File or Path not found.\n"); sprintf(status_information,"File or Patch not found."); exitstatus=CRITICAL; printf("%s: - %s\n",exit_status[exitstatus],status_information); return exitstatus; } else { fprintf(stderr,"Other error.\n"); sprintf(status_information,"Other error."); exitstatus=CRITICAL; printf("%s: - %s | %s\n",exit_status[exitstatus],status_information); return exitstatus; } }// printf("file st_mtime=%d\n",getstat.st_mtime);// printf("file st_ctime=%d\n",getstat.st_ctime); result=timestamp-getstat.st_mtime;// printf("now_time-st_mtime=%d\n",result);// ret=is_master_or_slave(); ret=1; if(result>=istime) { if(ret==1) { // sprintf(status_information,"is Master, access.log Status=%d Second=%d",0,result); sprintf(status_information,"mqsgip.log is %d seconds before modify, Second=%d",result,result); // sprintf(performance_data,"Status=%d;;;; Second=%d;;;;",0,result); sprintf(performance_data,"Second=%d;;;;",result); exitstatus=CRITICAL; } else { // sprintf(status_information,"is Slave, access.log Status=%d Second=%d",0,result); sprintf(status_information,"mqsgip.log Second=%d",result); // sprintf(performance_data,"Status=%d;;;; Second=%d;;;;",0,result); sprintf(performance_data,"Second=%d;;;;",result); exitstatus=OK; } } else { if(ret==1) { // sprintf(status_information,"is Master, access.log Status=%d Second=%d",1,result); sprintf(status_information,"mqsgip.log is %d seconds before modify, Second=%d",result,result); // sprintf(performance_data,"Status=%d;;;; Second=%d;;;;",1,result); sprintf(performance_data,"Second=%d;;;;",result); exitstatus=OK; } else { // sprintf(status_information,"is Slave, access.log Status=%d Second=%d",1,result); sprintf(status_information,"mqsgip.log Second=%d",result); // sprintf(performance_data,"Status=%d;;;; Second=%d;;;;",1,result); sprintf(performance_data,"Second=%d;;;;",result); exitstatus=OK; } } return 0;}int main() { int ret; int hour; char hour_str[LEN]; struct tm *tp; timestamp=time(NULL);// printf("now time=%d\n",timestamp); tp=localtime(×tamp); sprintf(hour_str,"%d",tp->tm_hour); hour=atoi(hour_str);// printf("hour=%d\n",hour); if(hour>=1 || hour<=7) { // ret=diff_time(LONG_TIME); ret=diff_time(SHORT_TIME); if(ret!=0) { fprintf(stderr,"diff_time(SHORT_TIME) error.\n"); } } else { ret=diff_time(SHORT_TIME); if(ret!=0) { fprintf(stderr,"diff_time(LONG_TIME) error.\n"); } } printf("%s: %s | %s\n",exit_status[exitstatus],status_information,performance_data); return exitstatus;}
0 0
- nagios插件之检测mqa的日志文件更新时间
- nagios插件之监控MQA日志文件
- nagios插件之监控MQA日志文件--检查ERROR
- nagios插件之检测文件修改时间
- nagios插件之监控mqa线程数
- nagios插件之监控文件更新时间
- nagios插件之检测tomcat日志的statusIndex值
- nagios插件之检测tomcat日志的startAt值(待改进)
- nagios插件之监控日志中CASA接口响应时间
- nagios插件之监控Asterisk日志文件--Master.cvs
- nagios插件之监控Asterisk日志文件--messages
- nagios插件之监控AES日志文件--检查ERROR
- nagios插件之监控if8接口日志
- nagios插件之监控单个tomcat日志
- nagios插件之监控oracle日志
- 如何修改nagios检测时间的单位
- nagios系列(五)之nagios图形显示的配置及自定义插件检测密码是否修改详解
- nagios插件之监控if8接口日志(新接口)
- pcap文件格式分析
- java内存模型
- 文章标题
- 怀念以前,珍惜现在,憧憬未来
- 5.Kth Largest Element-第k大元素(中等题)
- nagios插件之检测mqa的日志文件更新时间
- ASP.Net 关于前台JS给input赋值后,runat="server" 后台利用ID.Value还是获取不到的问题
- C语言(1)------Hello Word程序输出
- 文章标题
- 机器人动力学方程的性质
- hackintosh手动修复权限、重建缓存
- Hdu-5893 List wants to travel(树链剖分)
- 文章标题
- RAFT中成员变更过程以及失败回滚分析