Resources

Explore our blogs, guides, case studies, eBooks, and more actionable insights to enhance your IT monitoring and observability.

View Resources

About us

Get to know LogicMonitor and our team.

About us

Documentation

Read through our documentation, check out our latest release notes, or submit a ticket to our world-class customer service team.

View Resources

Internal Web Checks using Groovy Scripts with LM Uptime

Last updated on 10 July, 2025

Disclaimer: The LM Uptime is currently in Beta. To be a Beta participant, contact Customer Success.

You can execute your Internal Web Checks using a groovy script to collect and process HTTP data. Internal Web Checks with at least a single step that runs using Groovy script consist of a Step Request script and a Step Response processor. Step Request can send a GET request to collect the authenticating token for the site and share the token, while the Step Response authenticates into the site. 

The following are some of the benefits of creating Internal Web Checks using Groovy scripts:

  • Flexible authentication—Works well with form-based authentication that uses dynamic tokens
  • Context sharing—Pass authentication tokens between steps for seamless session continuity

API Commands for Groovy Scripts

The request script uses the Groovy API to get an HTTP response, which the response script then parses to apply post-processing methods such as checking the status or evaluating the response body.

API Commands for a Request Groovy Script

The following table lists the API commands you may use in your request Groovy script:

API Return type Description Default value (if applicable)
setAuthType(AuthType authType)LMRequestSet the Authentication Type  
setUsername(String username)LMRequestSet the Authentication username  
setPassword(String password)LMRequestSet the Authentication password  
setDomain(String domain)LMRequestSet the Authentication Domain (only for NTLM Authentication) 
followRedirect(boolean)LMRequestSpecifies whether or not redirects should be followedTrue
addHeader(String name, String value)LMRequestAdd the HTTP headers 
userHttp1_0()LMRequestSpecifies if HTTP/1.0 protocol version is usedFalse
userHttp1_1()LMRequestSpecifies if HTTP/1.1 protocol version is usedTrue
needFullpageLoad()LMRequestSpecifies if the full page needs to be loadedFalse
setContext(String name, Object value)LMHttpClientSet the context for the next scripts 
getContext(String name)ObjectGet the context of the previous scripts 
request(LMRequest)LMHttpClientSet the HTTP request parameters 
get()StatusCodeGET the Request and Return status.  
get(URL)StatusCodeGET the Request and Return status.  
head()StatusCodeCheck if the URL exists 
post(URL, PostDataType, String PostData)StatusCodePost the HTTP data 
setProxy(String hostname, int port, String schema)LMRequestSet the HTTP proxy. Schema can only be HTTP or HTTPS 
setProxy(String hostname, int port, String schema, String proxyUsername, String proxyPassword)LMRequestSet the HTTP proxy along with credentials. 

API Commands for a Response Groovy Script

The following table lists the API calls you may use in your response Groovy script:

API Command Return type Description
getStatus()IntegerReturn the HTTP status code
getReasonPhase()StringReturn the HTTP Reason Phase
getProtocolVersion()StringReturn the HTTP Protocol Version
getHeaders()Map (String, List [String]) Return all the headers
getHeader(String name)ListReturn the header value with name. If the header does not exist, a “null” response will be returned. Note that the name is case sensitive
getBody()StringReturn the HTTP Response Body
statusMatch(int expected)StatusCodeCheck if the status is as expected. If so, this will return STATUS_OK. Otherwise it will return STATUS_STATUS_MISMATCH
regexMatch(String pattern)StatusCodeCheck if the regex pattern matches the HTTP Response Body. If it fails, return STATUS_CONTENTS_MISMATCH
globMatch(String pattern)StatusCodeCheck if the regex pattern matches the HTTP Response Body. If it fails, return STATUS_CONTENTS_MISMATCH
plainTextMatch(String pattern)StatusCodeCheck if the HTTP Response Body contains the plain text. If it fails, return STATUS_CONTENTS_MISMATCH
jsonMatch(String path, String expectValue)StatusCodeCheck if the path’s JSON result matches the expect value. If it fails, return STATUS_CONTENTS_MISMATCH
PathMatch(String path, String expectValue)StatusCodeCheck if the string’s path matches the expect value. If it fails, return STATUS_CONTENTS_MISMATCH
keyValueMatch(String key, String expectValue)StatusCodeCheck if the returned key/Values match the expect value. If it fails, return STATUS_CONTENTS_MISMATCH
setContext(String name, Object value)voidSets the context for the next stages of your script
getContext(String)ObjectReturn the context set in a previous script stage

Status Codes

Code Value Description
STATUS_OK1Data collection functioned as expected
STATUS_MISMATCH11The HTTP response status does not match
STATUS_CONTENTS_MISMATCH12The HTTP Request did not return expected HTTP Response body

Requirements for Creating Internal Web Checks using Groovy Scripts with LM Uptime

To create internal web checks using groovy scripts, you need the following:

Creating Internal Web Checks using Groovy Scripts with LM Uptime

  1. In LogicMonitor, navigate to Resource Tree > Add icon.
  2. In the Uptime section, select Internal Web Check.
  3. Select the Basic and enter the required details.
  4. Select the Settings tab and do the following:
    1. In the Default Root URL section, select http:// or https:// protocol depending on your web server settings, and enter the website domain to which your Web Check request will be sent.
    2. In the Step One URL Path field, enter the first path that should be tested for your website. Enter the path relative to the website domain (For example, /folder/page.htm).
    3. In the Request section, select the Script tab.
    4. Toggle on the Use Groovy Script for Request (ignore Settings) switch.
    5. Select Generate Script from Settings to have LogicMonitor auto-generate request scripts based on those settings.
      The following Groovy syntax would be used in the first step of an Internal Web Check for a site using basic authentication:
      import com.logicmonitor.service.groovyapi.AuthType; import com.logicmonitor.service.groovyapi.LMRequest; LMRequest request = new LMRequest(); request.setAuthType(AuthType.BASIC) .setUsername("username") .setPassword("password") .followRedirect(false) .useHttp1_0() .needFullpageLoad(true); String jsonData = "{\"name\": \"value\"}" return LMHttpClient.request(request) .post(JSON, jsonData);

      For example, setContext() response:
      StatusCode status = LMResponse.statusMatch(200); LMResponse.setContext("body", Response.getBody()); return status;

      For example getContext() response:

      return LMResponse.plainTextmatch(Response.getContext("exampletext"))

      For example post(PostDataType, String PostData) response:
      import static com.logicmonitor.service.groovyapi.StatusCode.*; import static com.logicmonitor.service.groovyapi.PostDataType.*; String jsonData = "{\"name\": \"value\"}"; return LMHttpClient.post(JSON, jsonData);

      For example request(LMRequest) response:

      import com.logicmonitor.service.groovyapi.AuthType; import com.logicmonitor.service.groovyapi.LMRequest; LMRequest request = new LMRequest(); request.setAuthType(AuthType.BASIC) .setUsername("username") .setPassword("password") .followRedirect(false) .useHttp1_0() .needLoadFullPage(false); String jsonData = "{\"name\": \"value\"}" return LMHttpClient.request(request) .post(JSON, jsonData);
    6. Select the Script tab under the Response section.
    7. Toggle on the Use Groovy Script for Response (ignore Settings) switch.
    8. Select Generate Script from Settings to have LogicMonitor auto-generate response scripts based on those settings.
      For example, In the event that you wanted to verify a response status of “302” for a site, use the following request:

      import com.logicmonitor.service.groovyapi.LMRequest; LMRequest request = new LMRequest(); return LMHttpClient.request(request.followRedirect(false) .get());

      You would write your response script as follows:
      return LMResponse.statusMatch(302);

      Request and response script tabs
  5. Select the Checkpoints tab step and specify the Collectors that will send the checks.
    The Use Default Uptime Settings toggle is selected by default.
    Checkpoints tab groovy scripts page

Note: Your user account must have Collector view permissions to view and select Collectors from this area of the dialog. For more information, see Roles.

  1. Select the Alert Triggering tab and enter the required details.
  2. Select Save.
     The internal web check is added to the resources. 
In This Article

Start Your Trial

Full access to the LogicMonitor platform.
Comprehensive monitoring and alerting for unlimited devices.