Browse Source

Verified start/stop functionality with status.second logging in append

mode.


git-svn-id: https://svn.microneil.com/svn/SNFUtility/trunk@25 aa37657e-1934-4a5f-aa6d-2d8eab27ff7c
master
adeniz 12 years ago
parent
commit
28dbce670f
3 changed files with 126 additions and 63 deletions
  1. 86
    31
      Common/UtilityConfig.cpp
  2. 10
    2
      Common/UtilityConfig.hpp
  3. 30
    30
      SNFMilterConfig/SNFMilterConfigTests.txt

+ 86
- 31
Common/UtilityConfig.cpp View File

} }
FileName += ".log";
if (CFGData.Scan_XML_Mode) {
FileName += ".xml";
}
FileName += ".log.xml";
return FileName; return FileName;
} }
FileName += ".log";
if (CFGData.Scan_XML_Mode) {
FileName += ".xml";
}
FileName += ".log.xml";
return FileName; return FileName;
if (CFGData.Logs_Rotation_LocalTime_OnOff) { if (CFGData.Logs_Rotation_LocalTime_OnOff) {
BrokenDownTime = gmtime(&Timestamp);
BrokenDownTime = localtime(&Timestamp);
} else { } else {
BrokenDownTime = localtime(&Timestamp);
BrokenDownTime = gmtime(&Timestamp);
} }
UtilityConfig::GetSnifferStatusReport() { UtilityConfig::GetSnifferStatusReport() {
std::string StatusReport; std::string StatusReport;
int SleepTime_msec;
int TimeoutTime_msec;
switch (GetPreferredStatusCheckMethod()) { switch (GetPreferredStatusCheckMethod()) {
case StatusCheckSecond: case StatusCheckSecond:
StatusReport = GetReportViaLogFile(GetStatusSecondLogFileName(), 5000);
SleepTime_msec = 1000;
TimeoutTime_msec = 7000;
StatusReport = GetReportViaLogFile(&UtilityConfig::GetStatusSecondLogFileName, SleepTime_msec, TimeoutTime_msec);
break; break;
case StatusCheckMinute: 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(); std::cout.flush();
StatusReport = GetReportViaLogFile(GetStatusMinuteLogFileName(), 70 * 1000);
StatusReport = GetReportViaLogFile(&UtilityConfig::GetStatusMinuteLogFileName, SleepTime_msec, TimeoutTime_msec);
std::cout << "done." << std::endl; std::cout << "done." << std::endl;
break; break;
} }
std::string 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()) { if (Verbose()) {
cout << "Getting Sniffer status report via log file " << LogFileName << "...";
cout << "\nGetting Sniffer status report via log file " << LogFileName << "...";
std::cout.flush(); std::cout.flush();
} }
InitialContents = ReadLastPartOfFile(LogFileName, LogFileReportSize); // Read last part of log file. 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(); OutputVerboseEnd();
return FinalContents;
return "";
} }
if (SnifferIsStopped == GetRunningState(ApplicationName)) { if (SnifferIsStopped == GetRunningState(ApplicationName)) {
std::cout << ApplicationName << " is already not running.\n";
std::cout << ApplicationName << " was not running.\n";
return; return;
} }

+ 10
- 2
Common/UtilityConfig.hpp View File

StatusCheckNotAvailable ///< No method for checking is available. 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. /// Determine the mode for checking the status of Sniffer.
// //
// This method determines how the status of the sniffer should be // This method determines how the status of the sniffer should be
// interval. If the log file contents are different, then the // interval. If the log file contents are different, then the
// Sniffer is running. Otherwise, the Sniffer is not running. // 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 // \param[in] SleepTime_msec is the length of time to wait between
// log file reads. // 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 // \returns Status report obtained from Sniffer using the
// specified log file if the Sniffer is running. Otherwise, "" is // specified log file if the Sniffer is running. Otherwise, "" is
// returned. // 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 ConfigFileName; ///< Configuration file name.
std::string LicenseId; ///< License ID string. std::string LicenseId; ///< License ID string.

+ 30
- 30
SNFMilterConfig/SNFMilterConfigTests.txt View File

Start/stop functionality with XCI disabled, status.second enabled 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. 1) Disable XCI.




3) Enable status.minute logging, with append. 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 1) Run "SNFMilterConfig -start -v", and verify that SNFMilter
starts. starts.


2) Run "SNFMilterConfig -start -v" again and verify that SNFMilter 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. 3) Run "SNFMilterConfig -stop -v" and verify that SNFMilter stops.


4) Run "SNFMilterConfig -stop -v" again and verify that SNFMilter is 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 START_STOP_SEC-02: Repeat START_STOP_SEC-01 but without "-v" in the
command-line. command-line.


Result:
Result: Pass


START_STOP_SEC-03: Configure as for START_STOP_SEC-01, and do the START_STOP_SEC-03: Configure as for START_STOP_SEC-01, and do the
following: following:


1) Run SNFMilterConfig with "-start -explain". Verify correct 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 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. 3) Start SNFMilter.


4) Run SNFMilterConfig with "-start -explain". Verify correct 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 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. 1) Disable XCI.




3) Enable status.minute logging, with append. 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: Result:



Loading…
Cancel
Save