本文整理汇总了C++中Alarm::getAlarmID方法的典型用法代码示例。如果您正苦于以下问题:C++ Alarm::getAlarmID方法的具体用法?C++ Alarm::getAlarmID怎么用?C++ Alarm::getAlarmID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Alarm
的用法示例。
在下文中一共展示了Alarm::getAlarmID方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
if (strcmp (argv[1], AGENT_TRAP) == 0)
{
calAlarm.setPid (0);
calAlarm.setTid (0);
}
// process trap continues to get pid from alarm data
else
{
// pid
try {
token = getNextToken();
} catch (runtime_error& e)
{
if (::DEBUG) {
LoggingID lid(11);
MessageLog ml(lid);
Message msg;
Message::Args args;
args.add("getNextToken error:");
args.add(e.what());
msg.format(args);
ml.logDebugMessage(msg);
}
exit(1);
}
calAlarm.setPid (atoi(token));
// tid
try {
token = getNextToken();
} catch (runtime_error& e)
{
if (::DEBUG) {
LoggingID lid(11);
MessageLog ml(lid);
Message msg;
Message::Args args;
args.add("getNextToken error:");
args.add(e.what());
msg.format(args);
ml.logDebugMessage(msg);
}
exit(1);
}
calAlarm.setTid (atoi(token));
}
if (::DEBUG){
LoggingID lid(11);
MessageLog ml(lid);
Message msg;
Message::Args args;
args.add("Alarm Info:");
args.add(calAlarm.getAlarmID());
args.add(calAlarm.getComponentID());
args.add(calAlarm.getState());
msg.format(args);
ml.logDebugMessage(msg);
cout << calAlarm.getAlarmID() << ":"
<< calAlarm.getComponentID() << ":"
<< calAlarm.getState() << endl;
}
// break while loop. ignore the other info carried by
// the trap. May need to retrieve more info in the future.
break;
}
// not valid alarm data if no "CALALARM" found
if (!successFlag){
LoggingID lid(11);
MessageLog ml(lid);
Message msg;
Message::Args args;
args.add("Error: not valid alarm data if no 'CALALARM' found");
msg.format(args);
ml.logDebugMessage(msg);
exit(1);
}
// Get alarm configuration
try {
configAlarm (calAlarm);
} catch (runtime_error& e)
{
if (::DEBUG) {
LoggingID lid(11);
MessageLog ml(lid);
Message msg;
Message::Args args;
args.add("configAlarm error:");
args.add(e.what());
msg.format(args);
ml.logDebugMessage(msg);
}
exit(1);
}
return 0;
}
示例2: getAlarm
/*****************************************************************************************
* @brief getAlarm API
*
* purpose: Get List of Historical Alarms from alarm file
*
* date = MM/DD/YY format
*
*****************************************************************************************/
void SNMPManager::getAlarm(std::string date, AlarmList& alarmList) const
{
string alarmFile = "/tmp/alarms";
//make 1 alarm log file made up of archive and current alarm.log
(void)system("touch /tmp/alarms");
string cmd = ("ls " + ALARM_ARCHIVE_FILE + " | grep 'alarm.log' > /tmp/alarmlogfiles");
(void)system(cmd.c_str());
string fileName = "/tmp/alarmlogfiles";
ifstream oldFile (fileName.c_str());
if (oldFile) {
char line[200];
string buf;
while (oldFile.getline(line, 200))
{
buf = line;
string cmd = "cat " + ALARM_ARCHIVE_FILE + "/" + buf + " >> /tmp/alarms";
(void)system(cmd.c_str());
}
oldFile.close();
unlink (fileName.c_str());
}
cmd = "cat " + ALARM_FILE + " >> /tmp/alarms";
(void)system(cmd.c_str());
int fd = open(alarmFile.c_str(),O_RDONLY);
if (fd == -1)
// doesn't exist yet, return
return;
ifstream hisAlarm (alarmFile.c_str(), ios::in);
// acquire read lock
if (flock(fd,LOCK_SH) == -1)
{
throw runtime_error ("Lock alarm log file error");
}
//get mm / dd / yy from incoming date
string mm = date.substr(0,2);
string dd = date.substr(3,2);
string yy = date.substr(6,2);
Alarm alarm;
while (!hisAlarm.eof())
{
hisAlarm >> alarm;
if (alarm.getAlarmID() != INVALID_ALARM_ID) {
time_t cal = alarm.getTimestampSeconds();
struct tm tm;
localtime_r(&cal, &tm);
char tmp[3];
strftime (tmp, 3, "%m", &tm);
string alarm_mm = tmp;
alarm_mm = alarm_mm.substr(0,2);
strftime (tmp, 3, "%d", &tm);
string alarm_dd = tmp;
alarm_dd = alarm_dd.substr(0,2);
strftime (tmp, 3, "%y", &tm);
string alarm_yy = tmp;
alarm_yy = alarm_yy.substr(0,2);
if ( mm == alarm_mm && dd == alarm_dd && yy == alarm_yy )
//don't sort
// alarmList.insert (AlarmList::value_type(alarm.getAlarmID(), alarm));
alarmList.insert (AlarmList::value_type(INVALID_ALARM_ID, alarm));
}
}
hisAlarm.close();
unlink (alarmFile.c_str());
// release lock
if (flock(fd,LOCK_UN) == -1)
{
throw runtime_error ("Release lock active alarm log file error");
}
if (CALPONT_SNMP_DEBUG)
{
AlarmList :: iterator i;
for (i = alarmList.begin(); i != alarmList.end(); ++i)
{
cout << i->second << endl;
}
}
//.........这里部分代码省略.........