nagios插件之监控文件更新时间
来源:互联网 发布:ip网络广播软件源文件 编辑:程序博客网 时间:2024/06/05 17:29
vi check_file_updae_time.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 "/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;// timestamp=time(NULL);// printf("now time=%d\n",timestamp); ret=stat(LOG_FILE,&getstat); if(ret==-1) { if(errno==ENOENT) { fprintf(stderr,"File or Patch 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 time=%d\n",getstat.st_mtime); result=timestamp-getstat.st_mtime;// printf("result=%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(performance_data,"Status=%d;;;; Second=%d;;;;",0,result); exitstatus=CRITICAL; } else { sprintf(status_information,"is Slave, access.log Status=%d Second=%d",0,result); sprintf(performance_data,"Status=%d;;;; Second=%d;;;;",0,result); exitstatus=OK; } } else { if(ret==1) { sprintf(status_information,"is Master, access.log Status=%d Second=%d",1,result); sprintf(performance_data,"Status=%d;;;; Second=%d;;;;",1,result); exitstatus=OK; } else { sprintf(status_information,"is Slave, access.log Status=%d Second=%d",1,result); sprintf(performance_data,"Status=%d;;;; Second=%d;;;;",1,result); exitstatus=OK; } } return 0;}int main() { int ret; int hour; char hour_str[LEN]; struct tm *tp; timestamp=time(NULL); 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); 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插件之监控文件更新时间
- nagios插件之检测mqa的日志文件更新时间
- nagios插件之监控MQA日志文件
- nagios插件之检测文件修改时间
- nagios插件之监控日志中CASA接口响应时间
- nagios插件之监控Asterisk日志文件--Master.cvs
- nagios插件之监控Asterisk日志文件--messages
- nagios插件之监控MQA日志文件--检查ERROR
- nagios插件之监控AES日志文件--检查ERROR
- nagios插件之系统打开文件数监控
- nagios插件之监控POI搜索情况
- nagios插件之监控web页面登陆
- nagios插件之监控获取driverID
- nagios插件之监控casa业务
- nagios插件之监控if8接口日志
- nagios插件之域名超时监控
- nagios插件之监控单个tomcat日志
- nagios插件之监控oracle日志
- 【视频】Excel2013十大企业级明星函数视频课程【精讲】
- HDU5592(线段树+二分)
- iOS中int,float怎么保存在NSMutableArray中
- 简单的数据查询
- 设计模式里的多态,答疑
- nagios插件之监控文件更新时间
- java集合框架中的数据结构
- adb命令集合
- git客户端命令常用操作
- Quartz2D---苹果官方的⼆维绘图引擎(绘制基本图形)
- IOCP WSASend()
- LeetCode First Missing Positive
- 拓胜培训Java,每天的点点滴滴。
- linux编辑文件后无法保存