LogicMonitor seeks to disrupt AI landscape with $800M strategic investment at $2.4B valuation to revolutionize data centers.

Learn More

Update Websites

Last updated on 29 June, 2022

You can use LogicMonitor’s REST API to programmatically update websites in your LogicMonitor account.

As with all of our API calls, authentication is required.

There are two ways to update a website:

  • PUT: A PUT request enables you to replace an entire website definition (and update fields in the process).  You should use PUT to update a website if you want to provide an updated JSON definition for the website.  Note that consistent with REST standards, any properties not specified in a PUT request will revert back to their default values.
  • PATCH: A PATCH request enables you to replace only certain fields for a website.  You should use PATCH if you don’t have the JSON definition for the website and you only want to update a few fields.

PUT

HTTP Method:PUT

URI: /service/services/{id}

Request Parameters:

Property

Description

Required?

Values

Type

name The name of the website Yes Service names are restricted to numbers, letters, and – and _ symbols String
type The type of the website Yes ping | webservice String
isInternal Whether or not the website is internal No true | false. Defaults to false Boolean
host The URL that the service is checking, without the scheme (e.g. http, https) Yes String
description The description of the website No This value defaults to a blank String String
serviceFolderId The Id of the folder that the website is in No This value defaults to 1 Integer
stopMonitoring If this value is true, monitoring is disabled for the website. Note that if monitoring is disabled then alerting will also be disabled for the website. No true | false. This value defaults to false Boolean
disableAlerting If this value is true, alerting is disabled for the website. Note that alerting will be disabled by default if monitoring is disabled for the website. No true | false. This value defaults to false Boolean
individualSmAlertEnable Indicates whether an alert will be triggered if the website fails a check from an individual test location. No true | false. This value defaults to false Boolean
individualAlertLevel The level of alert to trigger if the service fails a check from an individual test location No warn | error | critical. This value defaults to warn String
overallAlertLevel The level of alert that is triggered if the website fails the number of check specified by transition from the test locations specified by globalSmAlertCond No warn | error | critical. This value defaults to warn String
pollingInterval How often the website is checked, in units of minutes. No 1-10 minutes. The value defaults to 5 Integer
clearTransition The number of checks that must be satisfied before an alert clears No This value defaults to 0 Integer
transition The number of checks that must fail before an alert is triggered No 1-10, 30, 60. This value defaults to 0 Integer
testLocation The test locations from which the website is monitored if it isn’t internal, OR the Collectors that should monitor the website if it’s internal. No You can specify Collectors like this: “{collectorIds:[12,89]}”. Non-internal Service locations include:

 

  • 0: Overall
  • 1: US – LA
  • 2: US – DC
  • 3: US – SF
  • 4: Europe – Dublin
  • 5: Asia – Singapore
  • 6: Australia – Sydney

You can specify one or more of these locations like this: “{smgIds:[1,2,3]}”

The default value is “{all:true}”

JSON Object
globalSmAlertCond The number of locations that the number of checks specified by transition must fail at in order to trigger an alert of severity overallAlertLevel. No

 

  • 0: all
  • 1: half
  • 2: more than one
  • 3: any

 

The default value is 0

 

Integer

For a ping service you can specify the following additional properties in your PUT request:

Property

Description

Required?

Values

Type

count The number of packets to send in the request No This value defaults to 5 Integer

For new Web Services the following additional properties apply:

Property

Description

Required?

Values

Type

steps An object comprising one or more steps, see the table below for the properties included in each step Yes See table below for more detail JSON Object
ignoreSSL Whether or not SSL should be ignored for each check No true | false. Defaults to false Boolean
pageLoadAlertTimeInMS The time in milliseconds that the page must load within for each step to avoid triggering an alert. No Defaults to 30000 Integer

The JSON object “steps” comprises one or more steps, where each step has the following properties:

Property

Description

Required

Values

Type

HTTPHeaders The headers included in the HTTP request to the web service No Any valid HTTP Header. E.g. “HTTPHeaders”:”Content-Type: application/json”. This value defaults to an empty string String
statusCode The expected response status code for the HTTP request made to the web service. Multiple status codes may be separated by commas No This value defaults to a blank String String
followRedirection If this value is true, the HTTP request to the web service will follow any redirects in place No true | false. This value defaults to false Boolean
matchType The type of interpretation method used to search for the keyword in the response No
  • plain: plain text
  • regular: regular expression
  • wildcard: glob expression

This value defaults to plain

String
keyword A string keyword that must be present in the response to the HTTP request made to the web service No This value defaults to a blank String String
HTTPBody The data in the body of the HTTP request to the web service No This value defaults to an empty string String
HTTPMethod The HTTP request method used in the request to the web service No GET | HEAD | POST. This value defaults to GET String
postDataEditType The format of the POST data Yes raw | json | xml | x-www-form-urlencoded String
url The URL for the step. This should be the full URL (i.e. domain + path) Yes String
fullpageLoad If this value is true then the HTTP request will wait for all page elements to load No true | false. This value defaults to false Boolean
requireAuth If this value is true then Authorization is required for the HTTP request to the web service No true | false. This value defaults to false Boolean
auth The authentication information required if requireAuth=true No The following parameters must be specified in this object:

 

  • type: common | basic | ntlm
  • userName
  • password
  • domain (only for type=ntlm)

e.g. “auth”:{“type”:”common”,”userName”:”test”,”password”:”example”}

JSON Object
invertMatch If this value is true, the keyword should not be present in the response No true | false. This value defaults to false. Boolean
timeout The number of seconds that the page must load within before the request should time out No 1 | 5 | 15 | 30 | 60 | 120 | 180. This value defaults to 30. Integer
HTTPVersion The HTTP version used in the request to the web service No 1.0 | 1.1. This value defaults to 1.1 String
schema The schema or protocol associated with the URL No http | https. This value defaults to http String
description The description associated with the step No Defaults to a blank string String
path The path associated with the step, where the path is the URL component after the domain No This value will be inferred from the url String
enable true | false. Whether or not the step is enabled No Defaults to true Boolean

For examples of these Website resource properties, see this page.

Example PUT: Update a website

The following Python request updates service 104:

#!/bin/env python

import requests
import json
import hashlib
import base64
import time
import hmac

#Account Info
AccessId ='ACCESS_ID'
AccessKey ='ACCESS_KEY'
Company = 'COMPANY_NAME'

#Request Info
httpVerb ='PUT'
resourcePath = '/service/services/104'
queryParams = ''
data='{"serviceFolderId":"1","type":"webservice","testLocation":"{\\"smgIds\\":[2, 3, 4]}","name":"ProdWebCheck","disableAlerting":true,"pollingInterval":5,"steps":[{"HTTPHeaders":"Content-Type:application/json","followRedirection":false,"keyword":"breaking","schema":"http","url":"www.google.com/#q=news","timeout":120},{"keyword":"california","url":"www.google.com/#q=states","invertMatch":true}]}'

#Construct URL 
url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resourcePath + queryParams

#Get current time in milliseconds
epoch = str(int(time.time() * 1000))

#Concatenate Request details
requestVars = httpVerb + epoch + data + resourcePath

#Construct signature
hmac1 = hmac.new(AccessKey.encode(),msg=requestVars.encode(),digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(hmac1.encode())

#Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth}

#Make request
response = requests.put(url, data=data, headers=headers)

#Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)
Python 3

PATCH

HTTP Method: PATCH

URI: /service/services/{id}

Request Parameters:

With every PATCH request you must include a query parameter patchFields that indicates which fields should be updated, where multiple fields should be comma separated.  If a field is identified in the patchFields parameter and included in the payload of the request, its value will be updated.  All other field values will remain the same.  E.g. to update a website’s name, the URI + query parameter would be /santaba/rest/service/services/{id}?patchFields=name.  The name field would also need to be included in the request payload.

Fields that can be updated by PATCH are:

  • name
  • description
  • serviceFolderId
  • stopMonitoring
  • disableAlerting
  • individualSmAlertEnable
  • individualAlertLevel
  • overallAlertLevel
  • pollingInterval
  • transition
  • globalSmAlertCond
  • testLocation
  • serviceProperties

Note that to add or update just one or a few service properties in the serviceProperties object, but not all of them, you’ll need to additionally use the opType query parameter. The opType query parameter can be set to add or replace. opType=add indicates that the properties included in the payload will be added, but all existing properties will remain the same. opType=replace indicates that the properties included in the request payload will be added if they don’t already exist, or updated if they do already exist, but all other existing properties will remain the same.

Example PATCH: Update a website

The following Python script updates website 11 via PATCH, and only adds one property.  All other fields will remain the same:

#!/bin/env python

import requests
import json
import hashlib
import base64
import time
import hmac

#Account Info
AccessId ='48v2wRzfK94y53sq5EuF'
AccessKey ='H_D9i(f5~B^U36^K6i42=^nS~e75gy382Bf6{)P+'
Company = 'api'

#Request Info
httpVerb ='PATCH'
resourcePath = '/service/services/11'
queryParams ='?patchFields=serviceProperties&opType=add'
data = '{"serviceProperties":[{"name":"project","value":"demo"}]}'

#Construct URL 
url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resourcePath + queryParams

#Get current time in milliseconds
epoch = str(int(time.time() * 1000))

#Concatenate Request details
requestVars = httpVerb + epoch + data + resourcePath

#Construct signature
hmac1 = hmac.new(AccessKey.encode(),msg=requestVars.encode(),digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(hmac1.encode())

#Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth}

#Make request
response = requests.patch(url, data=data, headers=headers)

#Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)
Python 3
In This Article