mode. git-svn-id: https://svn.microneil.com/svn/SNFUtility/trunk@25 aa37657e-1934-4a5f-aa6d-2d8eab27ff7cmaster
@@ -288,13 +288,7 @@ UtilityConfig::GetStatusSecondLogFileName(void) { | |||
} | |||
FileName += ".log"; | |||
if (CFGData.Scan_XML_Mode) { | |||
FileName += ".xml"; | |||
} | |||
FileName += ".log.xml"; | |||
return FileName; | |||
@@ -311,13 +305,7 @@ UtilityConfig::GetStatusMinuteLogFileName(void) { | |||
} | |||
FileName += ".log"; | |||
if (CFGData.Scan_XML_Mode) { | |||
FileName += ".xml"; | |||
} | |||
FileName += ".log.xml"; | |||
return FileName; | |||
@@ -335,11 +323,11 @@ UtilityConfig::AppendDatestampToLogFileName(std::string *FileBaseName) { | |||
if (CFGData.Logs_Rotation_LocalTime_OnOff) { | |||
BrokenDownTime = gmtime(&Timestamp); | |||
BrokenDownTime = localtime(&Timestamp); | |||
} else { | |||
BrokenDownTime = localtime(&Timestamp); | |||
BrokenDownTime = gmtime(&Timestamp); | |||
} | |||
@@ -485,6 +473,8 @@ std::string | |||
UtilityConfig::GetSnifferStatusReport() { | |||
std::string StatusReport; | |||
int SleepTime_msec; | |||
int TimeoutTime_msec; | |||
switch (GetPreferredStatusCheckMethod()) { | |||
@@ -495,14 +485,19 @@ UtilityConfig::GetSnifferStatusReport() { | |||
case StatusCheckSecond: | |||
StatusReport = GetReportViaLogFile(GetStatusSecondLogFileName(), 5000); | |||
SleepTime_msec = 1000; | |||
TimeoutTime_msec = 7000; | |||
StatusReport = GetReportViaLogFile(&UtilityConfig::GetStatusSecondLogFileName, SleepTime_msec, TimeoutTime_msec); | |||
break; | |||
case StatusCheckMinute: | |||
std::cout << "Getting Sniffer status from status.minute log file (this takes about 70 s)..."; | |||
SleepTime_msec = 10 * 1000; | |||
TimeoutTime_msec = 70 * 1000; | |||
std::cout << "Getting Sniffer status from status.minute log file (this takes about " | |||
<< TimeoutTime_msec / 1000 << " s)..."; | |||
std::cout.flush(); | |||
StatusReport = GetReportViaLogFile(GetStatusMinuteLogFileName(), 70 * 1000); | |||
StatusReport = GetReportViaLogFile(&UtilityConfig::GetStatusMinuteLogFileName, SleepTime_msec, TimeoutTime_msec); | |||
std::cout << "done." << std::endl; | |||
break; | |||
@@ -642,11 +637,15 @@ UtilityConfig::GetReportViaXci() { | |||
} | |||
std::string | |||
UtilityConfig::GetReportViaLogFile(std::string LogFileName, int SleepTime_msec) { | |||
UtilityConfig::GetReportViaLogFile(GetLogFileName GetLogFileNamePtr, int SleepTime_msec, int TimeoutTime_msec) { | |||
std::string LogFileName; | |||
LogFileName = (this->*GetLogFileNamePtr)(); | |||
if (Verbose()) { | |||
cout << "Getting Sniffer status report via log file " << LogFileName << "..."; | |||
cout << "\nGetting Sniffer status report via log file " << LogFileName << "..."; | |||
std::cout.flush(); | |||
} | |||
@@ -655,28 +654,84 @@ UtilityConfig::GetReportViaLogFile(std::string LogFileName, int SleepTime_msec) | |||
InitialContents = ReadLastPartOfFile(LogFileName, LogFileReportSize); // Read last part of log file. | |||
Sleeper Sleep(SleepTime_msec); // Wait 5 s. | |||
Sleep(); | |||
std::string FinalContents; | |||
int ElapsedTime_msec = 0; | |||
FinalContents = ReadLastPartOfFile(LogFileName, LogFileReportSize); // Read again. | |||
while (ElapsedTime_msec < TimeoutTime_msec) { | |||
bool IncreasedTimeoutTime = false; // TimeoutTime_msec can be increased | |||
// only once if the log file name changes. | |||
std::string NewLogFileName; | |||
Sleeper Sleep(SleepTime_msec); | |||
std::string FinalContents; | |||
if (InitialContents == FinalContents) { // If unchanged... | |||
Sleep(); | |||
if (Verbose()) { | |||
NewLogFileName = (this->*GetLogFileNamePtr)(); | |||
if (IncreasedTimeoutTime && (NewLogFileName != LogFileName)) { // Filename changes if it contains a | |||
// date stemp and the time is close | |||
// to midnight. | |||
TimeoutTime_msec *= 2; | |||
IncreasedTimeoutTime = true; | |||
if (Verbose()) { | |||
cout << "report unchanged..."; | |||
cout << "reading from " << NewLogFileName << "..."; | |||
std::cout.flush(); | |||
} | |||
} | |||
return ""; // ...there is no report. | |||
LogFileName = NewLogFileName; | |||
FinalContents = ReadLastPartOfFile(LogFileName, LogFileReportSize); // Read again. | |||
if (InitialContents != FinalContents) { // Contents have changed. | |||
if (Verbose()) { | |||
cout << "report changed..."; | |||
} | |||
OutputVerboseEnd(); | |||
std::string::size_type StatsStartPos; // Index of start of <stats> element. | |||
std::string::size_type StatsEndPos; // Index of end of <stats> element. | |||
StatsEndPos = FinalContents.rfind("</stats>"); | |||
if (std::string::npos == StatsEndPos) { | |||
throw std::runtime_error("Unable to interpret the status report: No '</stats>' closing tag found."); | |||
} | |||
StatsStartPos = FinalContents.rfind("<stats ", StatsEndPos); | |||
if (std::string::npos == StatsStartPos) { | |||
throw std::runtime_error("Unable to interpret the status report: No '<stats>' tag found."); | |||
} | |||
return FinalContents.substr(StatsStartPos); // Return the last <stats> element. | |||
} | |||
ElapsedTime_msec += SleepTime_msec; | |||
} | |||
if (Verbose()) { | |||
cout << "report unchanged..."; | |||
} | |||
OutputVerboseEnd(); | |||
return FinalContents; | |||
return ""; | |||
} | |||
@@ -1339,7 +1394,7 @@ UtilityConfig::StopSniffer(std::string ScriptAndArgs, std::string ApplicationNam | |||
if (SnifferIsStopped == GetRunningState(ApplicationName)) { | |||
std::cout << ApplicationName << " is already not running.\n"; | |||
std::cout << ApplicationName << " was not running.\n"; | |||
return; | |||
} |
@@ -393,6 +393,10 @@ private: | |||
StatusCheckNotAvailable ///< No method for checking is available. | |||
}; | |||
/// Typedef for pointer to member function that returns the log | |||
/// file name. | |||
typedef std::string (UtilityConfig::*GetLogFileName) (void); | |||
/// Determine the mode for checking the status of Sniffer. | |||
// | |||
// This method determines how the status of the sniffer should be | |||
@@ -453,16 +457,20 @@ private: | |||
// interval. If the log file contents are different, then the | |||
// Sniffer is running. Otherwise, the Sniffer is not running. | |||
// | |||
// \param[in] LogFileName is the name of the log file. | |||
// \param[in] GetLogFileNamePtr is pointer to the member function | |||
// that returns the log file name. | |||
// | |||
// \param[in] SleepTime_msec is the length of time to wait between | |||
// log file reads. | |||
// | |||
// \param[in] TimeoutTime_msec is the length of time to wait for | |||
// the file to change. | |||
// | |||
// \returns Status report obtained from Sniffer using the | |||
// specified log file if the Sniffer is running. Otherwise, "" is | |||
// returned. | |||
// | |||
std::string GetReportViaLogFile(std::string LogFileName, int SleepTime_msec); | |||
std::string GetReportViaLogFile(GetLogFileName GetLogFileNamePtr, int SleepTime_msec, int TimeoutTime_msec); | |||
std::string ConfigFileName; ///< Configuration file name. | |||
std::string LicenseId; ///< License ID string. |
@@ -177,9 +177,8 @@ START_STOP_XCI-03: Configure as for START_STOP_XCI-01, and do the following: | |||
Start/stop functionality with XCI disabled, status.second enabled | |||
----------------------------------------------------------------- | |||
START_STOP_SEC-01: Install default configuration files, and ensure | |||
that SNFMilter is stopped. Install configuration file | |||
SNFMilter_second.xml with the following configuration: | |||
START_STOP_SEC-01: Install configuration file SNFMilter_second.xml | |||
with the following configuration: | |||
1) Disable XCI. | |||
@@ -187,51 +186,50 @@ SNFMilter_second.xml with the following configuration: | |||
3) Enable status.minute logging, with append. | |||
Do the following, specifying the configuration file SNFMilter_second.xml: | |||
Do the following: | |||
1) Run "SNFMilterConfig -start -v", and verify that SNFMilter | |||
starts. | |||
2) Run "SNFMilterConfig -start -v" again and verify that SNFMilter | |||
is not started again. | |||
is still running. | |||
3) Run "SNFMilterConfig -stop -v" and verify that SNFMilter stops. | |||
4) Run "SNFMilterConfig -stop -v" again and verify that SNFMilter is | |||
not stopped again. | |||
still stopped. | |||
Result: | |||
Result: Pass | |||
START_STOP_SEC-02: Repeat START_STOP_SEC-01 but without "-v" in the | |||
command-line. | |||
Result: | |||
Result: Pass | |||
START_STOP_SEC-03: Configure as for START_STOP_SEC-01, and do the | |||
following: | |||
1) Run SNFMilterConfig with "-start -explain". Verify correct | |||
output, and that SNFMilterConfig doesn't start SNFMilter. | |||
output, and that SNFMilter is still stopped. | |||
2) Run SNFMilterConfig with "-stop -explain". Verify correct | |||
output, and that SNFMilterConfig doesn't stop SNFMilter. | |||
output, and that SNFMilter is still stopped. | |||
3) Start SNFMilter. | |||
4) Run SNFMilterConfig with "-start -explain". Verify correct | |||
output, and that SNFMilterConfig doesn't start SNFMilter. | |||
output, and that SNFMilter is still running. | |||
5) Run SNFMilterConfig with "-stop -explain". Verify correct | |||
output, and that SNFMilterConfig doesn't stop SNFMilter. | |||
output, and that SNFMilter is still running. | |||
Result: | |||
Result: Pass | |||
Start/stop functionality with XCI and status.second enabled, append mode | |||
------------------------------------------------------------------------ | |||
Start/stop functionality with XCI disabled and status.second enabled, append mode | |||
--------------------------------------------------------------------------------- | |||
START_STOP_SEC_APP-01: Install default configuration files, and ensure | |||
that SNFMilter is stopped. Create a configuration file | |||
SNFMilter_second_append.xml as follows: | |||
START_STOP_SEC_APP-01: Install configuration file | |||
SNFMilter_second_append.xml with the following configuration: | |||
1) Disable XCI. | |||
@@ -239,24 +237,26 @@ SNFMilter_second_append.xml as follows: | |||
3) Enable status.minute logging, with append. | |||
Do the following, specifying the configuration file SNFMilter_second_append.xml: | |||
4) Set localtime to "no" for rotation. | |||
Do the following when the local date is different from the date from | |||
gmtime(): | |||
1) Run "SNFMilterConfig -config=SNFMilter_second_append.xml -start", | |||
and verify that SNFMilter starts. | |||
1) Run "SNFMilterConfig -start -v", and verify that SNFMilter | |||
starts. | |||
2) Run "SNFMilterConfig -config=SNFMilter_second_append.xml -start" | |||
again and verify that SNFMilter is not started again. | |||
2) Run "SNFMilterConfig -start -v" again and verify that SNFMilter | |||
is still running. | |||
3) Run "SNFMilterConfig -config=SNFMilter_second_append.xml -stop" | |||
and verify that SNFMilter stops. | |||
3) Run "SNFMilterConfig -v -stop" and verify that SNFMilter stops. | |||
4) Run "SNFMilterConfig -config=SNFMilter_second_append.xml -stop" | |||
again and verify that SNFMilter is not stopped again. | |||
4) Run "SNFMilterConfig -stop -v" again and verify that SNFMilter is | |||
still stopped. | |||
Result: | |||
Result: Pass | |||
START_STOP_SEC_APP-02: Repeat START_STOP_SEC_APP-01 but with "-v" in | |||
the command-line. | |||
START_STOP_SEC_APP-02: Repeat START_STOP_SEC_APP-01 but without "-v" | |||
in the command-line. | |||
Result: | |||