- Added parameter System.ServiceState(*)
authorVictor Kirhenshtein <victor@netxms.org>
Tue, 19 Oct 2004 06:39:55 +0000 (06:39 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Tue, 19 Oct 2004 06:39:55 +0000 (06:39 +0000)
- New events added

ChangeLog
sql/events.in
src/agent/core/getparam.cpp
src/agent/core/win32.cpp

index 72bcf3c..fe7ce29 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+*
+* 0.1.6
+*
+
+- Added parameter System.ServiceState(*) to core agent (Windows only)
+
+
 *
 * 0.1.5
 *
@@ -13,6 +20,7 @@
 - All IP addresses now stored in database as text
 - Added external event sender (nxevent)
 - Fixed bug with user password change (new password was not saved to database)
+- Configuration script ("configure") improved
 
 
 *
index 25c834b..273430b 100644 (file)
@@ -5,7 +5,7 @@
 */
 
 #define THRESHOLD_EVENT_PARAMS \
-       '   1) Parameter name#0D#0A   2) Item description#0D#0A   3) Threshold value#0D#0A   4) Actual value'
+       '   1) Parameter name#0D#0A   2) Item description#0D#0A   3) Threshold value#0D#0A   4) Actual value#0D#0A   5) Parameter#27s argument'
 
 
 /*
@@ -289,7 +289,25 @@ INSERT INTO events (event_id,name,severity,flags,message,description) VALUES
        (
                4002, 'DC_HOST_RESTARTED',
                EVENT_SEVERITY_NORMAL, 1,
-               'Host has been restarted within last 5 minutes',
+               'Host was restarted within last 5 minutes',
+               'Custom data collection threshold event.#0D#0A' CONCAT
+               'Parameters:#0D#0A' CONCAT
+               THRESHOLD_EVENT_PARAMS
+       );
+INSERT INTO events (event_id,name,severity,flags,message,description) VALUES
+       (
+               4003, 'DC_AGENT_RESTARTED',
+               EVENT_SEVERITY_NORMAL, 1,
+               'NetXMS agent was restarted within last 5 minutes',
+               'Custom data collection threshold event.#0D#0A' CONCAT
+               'Parameters:#0D#0A' CONCAT
+               THRESHOLD_EVENT_PARAMS
+       );
+INSERT INTO events (event_id,name,severity,flags,message,description) VALUES
+       (
+               4004, 'DC_SERVICE_NOT_RUNNING',
+               EVENT_SEVERITY_MAJOR, 1,
+               'Service "%5" is not running',
                'Custom data collection threshold event.#0D#0A' CONCAT
                'Parameters:#0D#0A' CONCAT
                THRESHOLD_EVENT_PARAMS
index 6680dfd..ab40334 100644 (file)
@@ -49,6 +49,7 @@ LONG H_SystemUname(char *cmd, char *arg, char *value);
 LONG H_ThreadCount(char *cmd, char *arg, char *value);
 LONG H_NetIPStats(char *cmd, char *arg, char *value);
 LONG H_NetInterfaceStats(char *cmd, char *arg, char *value);
+LONG H_ServiceState(char *cmd, char *arg, char *value);
 #endif
 
 
@@ -174,6 +175,7 @@ static AGENT_PARAM m_stdParams[] =
    { "System.Memory.Virtual.Total", H_MemoryInfo, (char *)MEMINFO_VIRTUAL_TOTAL },
    { "System.Memory.Virtual.Used", H_MemoryInfo, (char *)MEMINFO_VIRTUAL_USED },
    { "System.ProcessCount", H_ProcCount, NULL },
+   { "System.ServiceState(*)", H_ServiceState, NULL },
    { "System.ThreadCount", H_ThreadCount, NULL },
    { "System.Uname", H_SystemUname, NULL },
 #endif
index bc85313..a30f93c 100644 (file)
@@ -321,3 +321,55 @@ LONG H_SystemUname(char *cmd, char *arg, char *value)
            versionInfo.dwMinorVersion, versionInfo.dwBuildNumber, osVersion, cpuType);
    return SYSINFO_RC_SUCCESS;
 }
+
+
+//
+// Handler for System.ServiceState parameter
+//
+
+LONG H_ServiceState(char *cmd, char *arg, char *value)
+{
+   SC_HANDLE hManager, hService;
+   TCHAR szServiceName[MAX_PATH];
+   LONG iResult = SYSINFO_RC_SUCCESS;
+
+   if (!NxGetParameterArg(cmd, 1, szServiceName, MAX_PATH))
+      return SYSINFO_RC_UNSUPPORTED;
+
+   hManager = OpenSCManager(NULL, NULL, GENERIC_READ);
+   if (hManager == NULL)
+   {
+      return SYSINFO_RC_ERROR;
+   }
+
+   hService = OpenService(hManager, szServiceName, SERVICE_QUERY_STATUS);
+   if (hService == NULL)
+   {
+      iResult = SYSINFO_RC_UNSUPPORTED;
+   }
+   else
+   {
+      SERVICE_STATUS status;
+
+      if (QueryServiceStatus(hService, &status))
+      {
+         int i;
+         static DWORD dwStates[7]={ SERVICE_RUNNING, SERVICE_PAUSED, SERVICE_START_PENDING,
+                                    SERVICE_PAUSE_PENDING, SERVICE_CONTINUE_PENDING,
+                                    SERVICE_STOP_PENDING, SERVICE_STOPPED };
+
+         for(i = 0; i < 7; i++)
+            if (status.dwCurrentState == dwStates[i])
+               break;
+         ret_uint(value, i);
+      }
+      else
+      {
+         ret_uint(value, 255);    // Unable to retrieve information
+      }
+      CloseServiceHandle(hService);
+   }
+
+   CloseServiceHandle(hManager);
+   return iResult;
+}