Source
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
/* QueryServiceConfig() and QueryServiceConfig2() maximum output buffer size */
/* as documented by Microsoft */
typedef enum
{
STARTUP_TYPE_AUTO,
STARTUP_TYPE_AUTO_DELAYED,
STARTUP_TYPE_MANUAL,
STARTUP_TYPE_DISABLED,
STARTUP_TYPE_UNKNOWN,
STARTUP_TYPE_AUTO_TRIGGER,
STARTUP_TYPE_AUTO_DELAYED_TRIGGER,
STARTUP_TYPE_MANUAL_TRIGGER
}
zbx_startup_type_t;
/******************************************************************************
* *
* Purpose: convert service state code from value used in Microsoft Windows *
* to value used in Zabbix *
* *
* Parameters: state - [IN] service state code (e.g. obtained via *
* QueryServiceStatus() function) *
* *
* Return value: service state code used in Zabbix or 7 if service state code *
* is not recognized by this function *
* *
******************************************************************************/
static zbx_uint64_t get_state_code(DWORD state)
{
/* these are called "Status" in MS Windows "Services" program and */
/* "States" in EnumServicesStatusEx() function documentation */
static const DWORD service_states[7] = {SERVICE_RUNNING, SERVICE_PAUSED, SERVICE_START_PENDING,
SERVICE_PAUSE_PENDING, SERVICE_CONTINUE_PENDING, SERVICE_STOP_PENDING, SERVICE_STOPPED};
DWORD i;
for (i = 0; i < ARRSIZE(service_states) && state != service_states[i]; i++)
;
return i;
}
static const char *get_state_string(DWORD state)
{
switch (state)
{
case SERVICE_RUNNING:
return "running";
case SERVICE_PAUSED:
return "paused";
case SERVICE_START_PENDING:
return "start pending";
case SERVICE_PAUSE_PENDING:
return "pause pending";
case SERVICE_CONTINUE_PENDING:
return "continue pending";
case SERVICE_STOP_PENDING:
return "stop pending";
case SERVICE_STOPPED:
return "stopped";
default:
return "unknown";
}
}
static const char *get_startup_string(zbx_startup_type_t startup_type)