Exemple #1
0
static void SegFault(int sig)
{
    int fid;
    const pstack_f *stk;
    
    /* default handler */
    signal(SIGSEGV, SIG_DFL);

    LogPrintf(LV_OOPS, "SegFault");
    /* print flow stack of thread */
    fid = FthreadSelfFlowId();
    if (fid != -1) {
        stk = FlowStack(fid);
        ProtStackFrmDisp(stk, TRUE);
    }
    else {
        fflush(NULL);
        if (mnp_pei != NULL)
            LogPrintfPei(LV_OOPS, mnp_pei, "Fault data saved in xml file");
        LogPrintf(LV_ERROR, "Thread without xplico's protol-stack (possible main flow)"); 
    }
    /* save to file in wireshark filter format all flows active in the time of fault */
    LogFault("Segmentation Fault");
    printf("Segmentation Fault: see log file and report it to the developers: [email protected]\n");
    fflush(NULL);
#if 0
    while (1)
        sleep(1);
#endif
    raise(SIGSEGV); /* call default handler*/
}
std::string CAlarmHandler::CheckFault(DataDictionary datum)
{
	_lastfault=_currentfault;
	_currentfault.clear();
	// what if multiple faults?
	for(int i=0; i< _faults.size(); i++)
	{
		if(datum.find(_faults[i]) == datum.end())
			continue;
		int npos  =  datum[_faults[i]].find('.');
		std::string level = datum[_faults[i]];
		std::string msg = datum[_faults[i]];

		if(npos!= std::string::npos) level =  Trim(datum[_faults[i]].substr(0,npos));
		if(npos!= std::string::npos) msg =  Trim(datum[_faults[i]].substr(npos+1));

		// FIXME: just grabs the first fault and leaves.
		if( (level != "Normal") && (stricmp(level.c_str(), "Unavailable")!=0))
		{	
			_currentfault=_faults[i]+ " " + datum[_faults[i]];

			if(_currentfault != _lastfault)
			{
				// cant continually reset
				_alarmdatum.clear();
				_alarmdatum["RaisedAt"] = datum["Timestamp"];
				_alarmdatum["Shift"] = datum["Shift"];
				_alarmdatum["RaisedBy"] = datum["Machine"];
				_alarmdatum["Severity"] = level;
				_alarmdatum["Description"] =_faults[i] + "-" + msg;
				_alarmdatum["ResolvedAt"] = datum["Timestamp"];
				_alarmdatum["Program"] = datum["program"];
				double dTBF = _tbftimer.elapsed();
				_tbftimer.restart();
				WriteRegistryTimeFailure(0);
				_alarmdatum["TBF"]=DataDictionary::HrMinSecFormat((double)dTBF); 
			}

			return _currentfault;
		}
	}
	if(!_lastfault.empty() && _currentfault.empty())
	{
		_alarmdatum["ResolvedAt"] = datum["Timestamp"];
		
		ptime start = GetDateTime(_alarmdatum["RaisedAt"]);
		ptime done = GetDateTime(_alarmdatum["ResolvedAt"]);
		time_duration duration = done - start;
		_alarmdatum["TTR"] = DataDictionary::HrMinSecFormat((double)duration.total_seconds()); 


		// FIXME: there can be multiple alarms simulataneously ...
		_allfaultdatum.push_back(_alarmdatum);
		_myfaultdatum.push_back(_alarmdatum);
		LogFault(_alarmdatum);

		if(_alarmdatum["Severity"] == "Fault")
		{

		}
	}
	return _currentfault;
}