Commit 7cc487b4 authored by Gilles Dubois's avatar Gilles Dubois
Browse files

Add inventory on service startup option (Disabled by default)

parent 4517a321
This diff is collapsed.
......@@ -174,6 +174,7 @@ BOOL COcsService::loadConfig()
m_iOldPrologFreq = GetPrivateProfileInt( OCS_SERVICE_SECTION, OCS_SERVICE_OLD_PROLOG_FREQ, DEFAULT_PROLOG_FREQ, csConfigFile);
m_iTToWait = GetPrivateProfileInt( OCS_SERVICE_SECTION, OCS_SERVICE_TTO_WAIT, -1, csConfigFile);
m_iWriteIniLatency = GetPrivateProfileInt( OCS_SERVICE_SECTION, _T( "WRITE_INI_LATENCY"), WRITE_TTOWAIT_EACH, csConfigFile);
m_iInventoryOnStatup = GetPrivateProfileInt(OCS_SERVICE_SECTION, OCS_SERVICE_INVENTORY_ON_STARTUP, INVENTORY_ON_STARTUP, csConfigFile);
return TRUE;
}
......@@ -204,6 +205,13 @@ BOOL COcsService::writeConfig( BOOL bFull)
LogEvent( EVENTLOG_ERROR_TYPE, EVMSG_GENERIC_ERROR, csValue);
bResult = FALSE;
}
csValue.Format(_T("%d"), m_iInventoryOnStatup);
if (!WritePrivateProfileString(OCS_SERVICE_SECTION, OCS_SERVICE_INVENTORY_ON_STARTUP, csValue, csConfigFile))
{
csValue.Format(_T("Failed to write new INVENTORY ON STARTUP Value : %s"), LookupError(GetLastError()));
LogEvent(EVENTLOG_ERROR_TYPE, EVMSG_GENERIC_ERROR, csValue);
bResult = FALSE;
}
protectConfigFiles();
return bResult;
}
......@@ -260,7 +268,7 @@ BOOL COcsService::OnInit()
writeConfig();
}
// Log service start
csMessage.Format( _T( "Service start parameters FREQ: %i, OLD_FREQ: %i, TTO_WAIT: %i"), m_iPrologFreq, m_iOldPrologFreq, m_iTToWait);
csMessage.Format(_T("Service start parameters FREQ: %i, OLD_FREQ: %i, TTO_WAIT: %i, INVENTORY_ON_STARTUP: %i"), m_iPrologFreq, m_iOldPrologFreq, m_iTToWait, m_iInventoryOnStatup);
LogEvent( EVENTLOG_INFORMATION_TYPE, EVMSG_GENERIC_MESSAGE, csMessage);
// Rotate log files
rotateLogs();
......@@ -274,6 +282,15 @@ BOOL COcsService::OnInit()
// Portect OCS files to prevent delete
protectCommonFiles();
protectConfigFiles();
// Check if inventoryOnStartUp is enabled and launch an inventory if needed
if (m_iInventoryOnStatup)
{
csMessage.Format(_T("Inventory on startup is enabled, run agent."));
LogEvent(EVENTLOG_INFORMATION_TYPE, EVMSG_GENERIC_MESSAGE, csMessage);
runAgent();
}
return TRUE;
}
......@@ -528,7 +545,7 @@ void COcsService::Run()
bNotifyInventory = FALSE;
m_iOldPrologFreq = m_iPrologFreq;
writeConfig();
csStatus.Format( _T( "OCS Inventory NG Agent executed successfully.\n\nNew service parameters: FREQ: %i, OLD_FREQ: %i, TTO_WAIT: %i"), m_iPrologFreq, vOld, m_iTToWait);
csStatus.Format( _T( "OCS Inventory NG Agent executed successfully.\n\nNew service parameters: FREQ: %i, OLD_FREQ: %i, TTO_WAIT: %i, INVENTORY_ON_STARTUP: %i"), m_iPrologFreq, vOld, m_iTToWait, m_iInventoryOnStatup);
LogEvent(EVENTLOG_INFORMATION_TYPE, EVMSG_GENERIC_MESSAGE, csStatus);
}
}
......
......@@ -25,7 +25,9 @@
#define OCS_SERVICE_RAND_FILE _T( "rand")
#define OCS_SERVICE_TTO_WAIT _T( "TTO_WAIT")
#define OCS_SERVICE_OLD_PROLOG_FREQ _T( "OLD_PROLOG_FREQ")
#define OCS_SERVICE_INVENTORY_ON_STARTUP _T( "INVENTORY_ON_STARTUP")
#define RUN_OCS _T( "ocsinventory.exe")
#define INVENTORY_ON_STARTUP 0 // 0 (no) by default
#define PROLOG_FREQ_UNIT 3600 // seconds
#define DEFAULT_PROLOG_FREQ 10 // * PROLOG_FREQ_UNIT
#define WRITE_TTOWAIT_EACH 60 // seconds
......@@ -84,6 +86,7 @@ protected:
int m_iPrologFreq; // Time between 2 agent run
int m_iOldPrologFreq; // Last time between 2 agent run
int m_iWriteIniLatency; // Time between TTO_WAIT write to file to save it
int m_iInventoryOnStatup; // Inventory on ocs agent start-up
CObArray m_tCommonHandles; // Handle of OCS common files to protect them from being deleted
CObArray m_tConfigHandles; // Handle of OCS config files to protect them from being deleted
};
......
......@@ -45,4 +45,5 @@ ProxyUser=
ProxyPwd=
[OCS Inventory Service]
INVENTORY_ON_STARTUP=1
PROLOG_FREQ=1
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment