Hey! These docs are for version 6.3, which is no longer officially supported. Click here for the latest version, 6.7!

Rest API Config endpoint for host templates

Object type: hosttemplate

Request URL: /rest/config/hosttemplate

Example GET:

{
   "object" : {
      "hosts" : [
         {
            "ref" : "/rest/config/host/7",
            "name" : "cisco"
         }
      ],
      "name" : "Cisco Mgt",
      "description" : "Cisco device Management URLs",
      "id" : "3",
      "has_icon" : 0,
      "servicechecks" : [
         {
            "ref" : "/rest/config/servicecheck/45",
            "name" : "Check Loadavg",
            "exception":"-w 5,5,5 -c 9,9,9",
            "timed_exception":null,
         },
         {
            "ref" : "/rest/config/servicecheck/4",
            "name" : "DNS",
            "exception":"--other --args",
            "timed_exception":null,
         },
         {
            "ref" : "/rest/config/servicecheck/6",
            "name" : "HTTP",
            "timed_exception":{
                "timeperiod" : { "name" : "workhours" },
                "args" : "--url=%URL% -w 15 -c 20",
            },
            "exception":null,
      ],
      "managementurls" : [
         {
            "url" : "ssh://$HOSTADDRESS$",
            "name" : "SSH",
            "id" : "4"
         },
         {
            "url" : "telnet://$HOSTADDRESS$",
            "name" : "Telnet",
            "id" : "5"
         }
      ],
      "uncommitted" : "1"
   }
}

Notes on attributes:

  • remove_hostservicechecks - see the Host Templates configuration section for information about this attribute.
  • has_icon - if set to 0, then there is no icon available. Otherwise will be set to epoch seconds as the time that the icon was updated. Icons can be found at /images/hticons/HTID/100×100.png, where HTID is the host template id number. There are also icons in 40×40.png and 20×20.png

Host Template - Upload

Host template is staged, parsed and checked for conflicts to see if an import would be successful.

Requires: ADMINACCESS.

URL: /rest/config/hosttemplate/upload

Method:

POST - upload new opspack
GET, PUT, DELETE - unimplemented
Headers:

Content-Type must be set to a form upload format, as the file will be uploaded
Parameters:

filename - file name to upload. Filename must not contain ".." or "/" or spaces
Will return status 200 unless there is an exceptional failure. Will log to audit log when submitted.

Returns for a failure with status 200:

{
 success: false,
 error: "Opspack contains ....", // If success is false, will return an internationalised string for display
}

Returns for a success:

{
 success: true,
 stdout: ['text from opspack','next line'], // Strings from the opspack test import process
 exists: true,                   // Returns true if there is any conflict in the opspack for importing. Details in the stdout
}

Host Template - Import

Requires: ADMINACCESS.

Needs changelog if enabled.

URL: /rest/config/hosttemplate/import

Method:

POST - import opspack
GET, PUT, DELETE - unimplemented
Parameters:

filename - opspack to import from the prior upload
overwrite - default 0. If 1, force import of opspack
changelog - required if changelog is enabled
Will log to audit log when submitted.

Returns:

{
 success: true,
 return_code: 0, // Return code from the opspack import process
 stdout: [],     // Array of strings from opspack import output
 stderr: [],     // Array of strings from opspack import errors
}

Example import script
This example script in perl, import_opspack_via_rest.pl, shows how to code the upload & import of an Opspack.

Host Template - Export Opspack

Prepares an opspack for export. Take the generated filename for retrieving in a subsequent call.

Requires: ADMINACCESS.

URL: /rest/config/hosttemplate/ID/export

Method:

POST - starts an opspack export
DELETE - unimplemented
Returns:

{
 success: true,
 filename: "FILENAME.opspack"  // Will be a generated temporary name
}

Host Template - Retrieve Opspack

Retrieves a previously exported opspack. When the file is downloaded, the file will be removed.

No specific access required.

URL: /rest/exportedFile

Method:

GET - retrieves an exported opspack
POST, PUT, DELETE - unimplemented
Parameters:

filename - opspack to retrieve. Use the temporary filename from the Export Opspack call
Returns the contents of the file, with a content type of "application/octet-stream".

Example export process

$ opsview_rest --username=admin --password=initial --pretty --data-format=json POST "config/hosttemplate/1/export"
{
   "filename" : "opsview-component-agent:tempcman1ESWWKpFnxx3.opspack",
   "success" : true
}

$ wget --header="Accept: application/json" -O saved.opspack "http://localhost/rest/exportedFile?filename=opsview-component-agent:tempcman1ESWWKpFnxx3.opspack"