The AccCheckDefsAPI script include enables managing check definitions and associated parameters.

This script include requires the Agent Client Collector Framework (sn_agent) store application and is provided within the sn_agent namespace. This API requires the agent_client_collector_admin role. For more information, refer to Agent Client Collector.

This API does not have a constructor for creating an instance. Call each method using the AccCheckDefsAPI static class in the following format:

sn_agent.AccCheckDefsAPI.<method>

For the REST API solution, refer to Agent Client Collector API .

This API includes methods that enable the following:
  • Get a specified check definition
  • Get a list of check definitions
  • Update checks and check parameters

AccCheckDefsAPI - getCheck(String checkDefId, Boolean withParams)

Gets a specified check definition with details.

Table 1. Parameters
Name Type Description
checkDefId String Sys_id of the check definition listed in the Check Definitions [sn_agent_check_def] table.
withParams Boolean Flag that indicates whether existing check parameter details are returned. Information for each standard and secure check parameter is included in a JSON object.
Valid values:
  • true: Return check parameter details.
  • false: Do not return check parameter details.

Default: False

Example

The following example shows how to get information for a specified check definition.

var checkDefId = "94436b237f705300f128134f8dfa91a4";
var withParams = true;

var checkDef = sn_agent.AccCheckDefsAPI.getCheck(checkDefId, withParams);

gs.info(JSON.stringify(checkDef, null, 2));

Output:

{
  "check": {
    "name": "app.apache.metrics-apache",
    "command": "metrics-apache-graphite.rb -p {{.labels.params_port}} --path {{.labels.params_path}} -h {{.labels.params_host}}",
    "plugins": [
      "monitoring-plugin-common"
    ],
    "timeout": 60,
    "proxy_valid": true,
    "background": false,
    "check_type": "Metrics",
    "check_group": "Apache",
    "sys_id": "94436b237f705300f128134f8dfa91a4",
    "params": [
      {
        "name": "port",
        "active": true,
        "mandatory": true,
        "default_value": "80",
        "sys_id": "58436b237f705300f128134f8dfa91a8"
      },
      {
        "name": "path",
        "active": true,
        "mandatory": true,
        "default_value": "/server-status?auto",
        "sys_id": "98436b237f705300f128134f8dfa91aa"
      },
      {
        "name": "scheme",
        "active": false,
        "mandatory": false,
        "default_value": null,
        "sys_id": "a4e57a96db3bbb4035305c55dc9619f6"
      },
      {
        "name": "host",
        "active": true,
        "mandatory": true,
        "default_value": "127.0.0.1",
        "sys_id": "d4436b237f705300f128134f8dfa91a6"
      },
      {
        "name": "ssl_secure_connection",
        "active": false,
        "mandatory": false,
        "default_value": null,
        "sys_id": "e3b272c4530100106ffeddeeff7b1275"
      }
    ],
    "secure_params": [
      {
        "name": "cred_user_name",
        "active": true,
        "order": 1,
        "sys_id": "2494cd6e53170010f42cddeeff7b1273"
      },
      {
        "name": "cred_password",
        "active": true,
        "order": 2,
        "sys_id": "35948d6e53170010f42cddeeff7b127f"
      }
    ]
  },
  "error": null
}

AccCheckDefsAPI - getChecksList(String encodedQuery, Number limit, Boolean withParams)

Gets a list of check definitions with details.

See also Checks and policies.

Table 3. Parameters
Name Type Description
encodedQuery String An encoded query string to filter the check definition result list. Use null for an unfiltered list of check definitions in the system.
limit Number Limits the number of returned records. Set to null to use the default value.

Default: 20,000

withParams Boolean Flag that indicates whether existing check parameter details are returned. Information for each standard and secure check parameter is included in a JSON object.
Valid values:
  • true: Return check parameter details.
  • false: Do not return check parameter details.

Default: False

Example

The following example shows how to retrieve a list of two check definitions with parameter values.

var encQuery = "nameSTARTSWITHchecks_";
var limit = 2;
var withParams = true;

var checkDefs = sn_agent.AccCheckDefsAPI.getChecksList(encQuery, limit, withParams);

gs.info(JSON.stringify(checkDefs, null, 2));

Output:

[
  {
    "name": "checks_api_test",
    "command": "echo hello",
    "plugins": [],
    "timeout": 9,
    "proxy_valid": true,
    "background": false,
    "check_type": "TestCheck",
    "check_group": "computer",
    "sys_id": "7f1f9026dba530106f4810284b96194f",
    "params": [],
    "secure_params": [
      {
        "name": "check_api_test_check_secure_param2",
        "active": true,
        "order": 2,
        "sys_id": "2d30a066dba530106f4810284b9619c1"
      },
      {
        "name": "check_api_test_check_secure_param1",
        "active": true,
        "order": 100,
        "sys_id": "4c20a066dba530106f4810284b9619a8"
      }
    ]
  },
  {
    "name": "checks_api_test222",
    "command": "echo hello1212121",
    "plugins": [],
    "timeout": 60,
    "proxy_valid": true,
    "background": false,
    "check_type": "TestCheck",
    "check_group": "computer",
    "sys_id": "99e12466dba530106f4810284b961976",
    "params": [
      {
        "name": "check_api_test_check_param_222",
        "active": true,
        "mandatory": false,
        "default_value": "test_test_test",
        "sys_id": "44026466dba530106f4810284b9619b2"
      }
    ],
    "secure_params": []
  }
]

AccCheckDefsAPI - updateCheck(String checkDefId, Object updateJson)

Enables changing one or more field values of a specified check definition.

See also Checks and policies.

Table 6. Returns
Type Description
None Error message if unsuccessful.

Example

The following example shows how to deactivate a check definition.

var checkJson = sn_agent.AccCheckDefsAPI.getCheck(activeCheckDefs[0].sys_id, true);
if (!gs.nil(checkJson.error))
	gs.error(checkJson.error);

var updateJson = {active: "0"}; // deactivate the check definition
sn_agent.AccCheckDefsAPI.updateCheck(checkJson.check.sys_id, updateJson);

AccCheckDefsAPI - updateCheckParam(String checkDefParamId, Object updateJson)

Enables changing one or more field values of a specified check parameter.

Table 8. Returns
Type Description
None Error message if unsuccessful.

Example

The following example shows how to activate a check parameter.

var checkParmSysId = "cd922ce6dba530106f4810284b961966";
var updateJson = {"active": "true"};
sn_agent.AccCheckDefsAPI.updateCheckSecureParam(checkParmSysId, updateJson);

AccCheckDefsAPI - updateCheckSecureParam(String checkDefSecureParamId, Object updateJson)

Enables changing one or more field values of a specified check secure parameter.

Table 10. Returns
Type Description
None Error message if unsuccessful.

Example

The following example shows how to activate a check secure parameter.

var checkSecParmSysId = "<sys_id>";
var updateJson = {"active": "true"};
sn_agent.AccCheckDefsAPI.updateCheckSecureParam(checkSecParmSysId, updateJson);