Sample Webcheck via Groovy Scripts to test-out!!!
In LM tool, you can choose to manually add your request and response Groovy scripts directly into the text boxes found under both of these Script tabs or, as shown next, you can choose to first complete the fields under the Settings tab (e.g.HTTP Version,Method,Follow redirect,Authentication Required,Headers,HTTP Response Format, etc.) and then click theGenerate Script from Settingsbutton to have LogicMonitor auto-generate request and response scripts based on those settigs. The latter option produces a basic template for your Groovy scripts. (For more information on completing the fields found under the Settings tab for both the HTTP request and response, seeAdding a Web Check). So with LM platform tool, you can alsoauto-generate request and response scriptsscript as shown in above screenshot. Now hereis an sample script to providing a code snippet in Groovy that's using the Santaba HTTP library to make an HTTP GET request to a specified URL (in this case, "https://www.google.com") and retrieve headers from the response. Additionally, it appearsto set basic authentication credentials for the request. The script here is just for reference,to test the scripted HTTP responses.This code block here is the part which makes the http get to google Here's a breakdown of your code: import com.santaba.agent.groovyapi.http.*; // Instantiate an http client object for the target system httpClient = HTTP.open(); // Set basic authentication credentials httpClient.setAuthentication("myusername", "mypassword"); // Specify the URL url = "https://www.google.com"; // Perform an HTTP GET request def getResponse = httpClient.get(url); // Get headers from the response headers = httpClient.getHeaders(); // Close the http client httpClient.close(); Alternatively you can leverage the LM tool to monitored the Few things to note for the code here : The code appears to be setting basic authentication credentials ( myusername and mypassword ), but it's important to note that sending credentials in plaintext might not be secure. Consider using HTTPS and more secure authentication methods if available. The code is making an HTTP GET request to the specified URL ( "https://www.google.com" ) and storing the response in the getResponse variable. After the request, the code retrieves headers from the response using httpClient.getHeaders() and stores them in the headers variable. Finally, the HTTP client is closed using httpClient.close() . Link for more references : https://www.logicmonitor.com/support/services/adding-managing-services/executing-internal-web-checks-via-groovy-scripts Example Request Script Commands Keep Learning & Keep Exploring with LM !!!!!! Interested in learning more about features of your LogicMonitor portal? Check our some of our webinars in our community!https://www.logicmonitor.com/live-training-webinars Sign up for self guided training by clicking the "Training" link at the top right of your portal. Check out our Academy resources!https://www.logicmonitor.com/academy/261Views20likes0Comments