The CheckInstanceTestBuilder script include provides methods that enable building test check requests on check instances.

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

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

This script include provides methods that enable the following:
  • Set the check instance to test
  • Set the configuration item to run the test against
You can also specify one of the following identifiers to use during the test:
  • Credential sys_id
  • Credential alias id
  • Credential name

CheckInstanceTestBuilder - CheckInstanceTestBuilder()

Creates an CheckInstanceTestBuilder instance.

Table 1. Parameters
Name Type Description
None

Example

The following example shows how to initialize CheckInstanceTestBuilder.

var builder = new sn_agent.CheckInstanceTestBuilder();

CheckInstanceTestBuilder - build()

Builds the test check request with the arguments set.

Table 2. Parameters
Name Type Description
None
Table 3. Returns
Properties Description
Object JSON object with two attributes – the test result record ID and an error. If the build is successful, the test result ID returns and error is null. If an error occurs during the build, the test result ID is null and the error displays.

Example

The following example shows how build a test check request:

var checkId = "158279505372b30034b8ddeeff7b1270";
var ciId = "cc0dcc855374301062d1ddeeff7b12b0";
var builder = new sn_agent.CheckInstanceTestBuilder();

var testResultJson = builder.withCheckId(checkId).withCiId(ciId).build();

if (!gs.nil(testResultJson.error))
	gs.error(testResultJson.error);

CheckInstanceTestBuilder - withCheckId(String checkId)

Sets the sys_id of the check definition to test.

Table 4. Parameters
Name Type Description
checkId String Sys_id of the check definition listed in the Check Definitions [sn_agent_check_def] table.
Table 5. Returns
Type Description
CheckInstanceTestBuilder The builder instance the method was invoked for.

Example

The following example shows how create a test check.

var checkId = "158279505372b30034b8ddeeff7b1270";
var ciId = "cc0dcc855374301062d1ddeeff7b12b0";
var builder = new sn_agent.CheckInstanceTestBuilder();
var testResultJson = builder.withCheckId(checkId).withCiId(ciId).build();
if (!gs.nil(testResultJson.error))
	gs.error(testResultJson.error);

CheckInstanceTestBuilder - withCiId(String ciId)

Sets the sys_id of the configuration item to run the test against.

Table 6. Parameters
Name Type Description
ciId String Sys_id of a CMDB Configuration Item.
Table 7. Returns
Type Description
CheckInstanceTestBuilder The builder instance the method was invoked for.

Example

The following example shows how to create a test check request with

var checkId = "158279505372b30034b8ddeeff7b1270";
var ciId = "cc0dcc855374301062d1ddeeff7b12b0";
var builder = new sn_agent.CheckInstanceTestBuilder();
var testResultJson = builder.withCheckId(checkId).withCiId(ciId).build();
if (!gs.nil(testResultJson.error))
	gs.error(testResultJson.error);

CheckInstanceTestBuilder - withCredentialsAliasId(String credentialsAliasId)

Sets the credentials alias sys_id to use during the test.

Note: Running this removes any previous assignment done by calling withCredentialsName, withCredentialsAliasId or withCredentialsAliasName.
Table 8. Parameters
Name Type Description
credentialsAliasId String Sys_id of a credentials alias record.
Table 9. Returns
Type Description
CheckInstanceTestBuilder The builder instance the method was invoked for.

Example

The following example shows how create a test check and set the credentials alias ID.

var checkId = "158279505372b30034b8ddeeff7b1270";
var credAlias = "<sys_id>";
var builder = new sn_agent.CheckInstanceTestBuilder();
var testResultJson = builder.withCheckId(checkId).withCredentialsAliasId(credAlias).build();
if (!gs.nil(testResultJson.error))
	gs.error(testResultJson.error);

CheckInstanceTestBuilder - withCredentialsAliasName(String credentialsAliasName)

Sets the credentials alias name to use during the test. If the given value matches the name of multiple credentials aliases records, then one of them is chosen randomly.

Note: Running this removes any previous assignment done by calling withCredentialsName, withCredentialsAliasId or withCredentialsAliasName.
Table 10. Parameters
Name Type Description
credentialsAliasName String Name of a credentials alias.
Table 11. Returns
Type Description
CheckInstanceTestBuilder The builder instance the method was invoked for.

Example

The following example shows how create a test check and set the credentials alias name.

var checkId = "158279505372b30034b8ddeeff7b1270";
var credentialsAliasName = "credentialsAliasName";
var builder = new sn_agent.CheckInstanceTestBuilder();
var testResultJson = builder.withCheckId(checkId).withCredentialsAliasName(credentialsAliasName).build();
if (!gs.nil(testResultJson.error))
	gs.error(testResultJson.error);

CheckInstanceTestBuilder - withCredentialsId(String credentialsId)

Sets the credentials sys_id to use during the test.

Note: Running this removes any previous assignment done by calling withCredentialsName, withCredentialsAliasId or withCredentialsAliasName.
Table 12. Parameters
Name Type Description
credentialsId String Sys_id of a credentials record.
Table 13. Returns
Type Description
CheckInstanceTestBuilder The builder instance the method was invoked for.

Example

The following example shows how create a test check and set the credentials ID.

var checkId = "158279505372b30034b8ddeeff7b1270";
var credID = "<sys_id>";
var builder = new sn_agent.CheckInstanceTestBuilder();
var testResultJson = builder.withCheckId(checkId).withCredentialsId(credID).build();
if (!gs.nil(testResultJson.error))
	gs.error(testResultJson.error);

CheckInstanceTestBuilder - withCredentialsName(String credentialsName)

Sets the credentials name to use during the test. If the given value is the name of several credentials records, then one of them is chosen randomly.

Note: Running this removes any previous assignment done by calling withCredentialsName, withCredentialsAliasId or withCredentialsAliasName.
Table 14. Parameters
Name Type Description
credentialsName String Name of the credentials record.
Table 15. Returns
Type Description
CheckInstanceTestBuilder The builder instance the method was invoked for.

Example

The following example shows how create a test check and set the credentials name.

var checkId = "158279505372b30034b8ddeeff7b1270";
var credname = "credentialsName";
var builder = new sn_agent.CheckInstanceTestBuilder();
var testResultJson = builder.withCheckId(checkId).withCredentialsName(credName).build();
if (!gs.nil(testResultJson.error))
	gs.error(testResultJson.error);

CheckInstanceTestBuilder - withProxyAgentId(String agentId)

Sets the agent to run the test. Allowed only in case the tested check instance and policy are proxy.

Table 16. Parameters
Name Type Description
agentId String Unique ID of an agent proxy to run this check. This value is listed in the Agent ID column of the Agent Client Collectors [sn_agent_cmdb_ci_agent] table.
Table 17. Returns
Type Description
CheckInstanceTestBuilder The builder instance the method was invoked for.

Example

The following example shows how create a test check and set the proxy agent ID.

var checkId = "158279505372b30034b8ddeeff7b1270";
var agentId = "<agentID>";
var builder = new sn_agent.CheckInstanceTestBuilder();
var testResultJson = builder.withCheckId(checkId).withAgentId(agentId).build();
if (!gs.nil(testResultJson.error))
	gs.error(testResultJson.error);