alarm.c

来自「GSM猫管理程序」· C语言 代码 · 共 62 行

C
62
字号
/*SMS Server Tools 3Copyright (C) Keijo Kasvihttp://smstools3.kekekasvi.com/Based on SMS Server Tools 2 from Stefan Fringshttp://www.meinemullemaus.de/This program is free software unless you got it under another license directlyfrom the author. You can redistribute it and/or modify it under the terms ofthe GNU General Public License as published by the Free Software Foundation.Either version 2 of the License, or (at your option) any later version.*/#include <limits.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <stdarg.h>#include <syslog.h>#include <time.h>#include "alarm.h"#include "extras.h"char* _alarmhandler={0};int _alarmlevel=LOG_WARNING;void set_alarmhandler(char* handler,int level){  _alarmhandler=handler;  _alarmlevel=level;}void alarm_handler0(int severity, char *devicename, char *text){  alarm_handler(severity, devicename, "%s", text);}void alarm_handler(int severity,char* devicename,char* format, ...){  va_list argp;  char text[1024];  char cmdline[PATH_MAX+1024];  char timestamp[40];  time_t now;  if (_alarmhandler[0])  {    va_start(argp,format);    vsnprintf(text,sizeof(text),format,argp);    va_end(argp);    if (severity<=_alarmlevel)    {      time(&now);      strftime(timestamp,sizeof(timestamp),"%Y-%m-%d %H:%M:%S",localtime(&now));      snprintf(cmdline,sizeof(cmdline),"%s ALARM %s %i %s \"%s\"",_alarmhandler,timestamp,severity,devicename,text);            my_system(cmdline, "alarmhandler");    }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?