Using Postman to create multiple Websites via API & CSV?
Hi, I’m testing out creating websites (or resources) via the API. I have a standard Post working in Postman just fine. However, when I then try to do the same thing via a CSV file in the Runner section, I’m getting 401 Authorization errors. When I look at the data that’s being sent, it looks the same as what’s sent when I run it manually. Is there something special I need to do when running a Post command via the Runner vs the manual Send command? Thanks.Solved407Views12likes40CommentsUsing REST API from ServiceNow Scripting
I would like to use the REST API from ServiceNow but I'm not able to generate the HMAC using the ServiceNow Glide System native class GlideCertificateEncryption(), the resulting values don't match with what I would expect from Python or PowerShell. Are there any ServiceNow developers out there who have managed to call the LogicMonitor REST API from a ServiceNow script?If you have, could anyone share an example script please. var JavaString = Packages.java.lang.String; var key = new JavaString("key"); var message = new JavaString("message"); var keyUTF8 = new JavaString(key.getBytes("UTF8")); var messageUTF8 = new JavaString(message.getBytes("UTF8")); var util = new GlideStringUtil(); var encryption = new GlideCertificateEncryption(); //var mac = encryption.generateMac(util.base64Encode(keyUTF8), "HMACSHA256", messageUTF8); var mac = encryption.generateMac(HexUtil.convertToBase64(keyUTF8 + ""), "HMACSHA256", messageUTF8 + ""); gs.log(mac); gs.log(HexUtil.convertToBase64(mac)); var decoded = util.base64Decode(mac); var utf8Bytes = decoded.getBytes("UTF8"); gs.log(utf8Bytes.length); gs.log(JSON.stringify(utf8Bytes));Solved399Views3likes7CommentsTrouble Authenticating to LogicMonitor REST API from ServiceNow
I am trying to convert a PowerShell script to run from ServiceNow and found “Using REST API from ServiceNow Scripting” from two years ago. Since then, ServiceNow has addedGlideDigest() which, among other things, should allow me to create a message digest from a string using the SHA256 algorithm, with the result being a Base64 string. However, I am getting back: "{"errorMessage":"Authentication failed","errorCode":1401,"errorDetail":null}" The PowerShell script looks like this: [string]$sandboxaccessid = 'abc' [securestring]$sandboxaccesskey = '123' | ConvertTo-SecureString -AsPlainText -Force [string]$AccountName = 'portalname' [int]$Id = 2 $httpVerb = "GET" $resourcePath = "/device/devices/$id" $AllProtocols = [System.Net.SecurityProtocolType]'Tls11,Tls12' [System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols $time = (Get-Date).ToUniversalTime() $epoch = [Math]::Round((New-TimeSpan -Start (Get-Date -Date "1/1/1970") -End $time).TotalMilliseconds) $requestVars = $httpVerb + $epoch + $resourcePath $hmac = New-Object System.Security.Cryptography.HMACSHA256 $hmac.Key = [Text.Encoding]::UTF8.GetBytes([System.Runtime.InteropServices.Marshal]::PtrToStringAuto(([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($sandboxaccesskey)))) $signatureBytes = $hmac.ComputeHash([Text.Encoding]::UTF8.GetBytes($requestVars)) $signatureHex = [System.BitConverter]::ToString($signatureBytes) -replace '-' $signature = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($signatureHex.ToLower())) $headers = @{ "Authorization" = "LMv1 $sandboxaccessid`:$signature`:$epoch" "Content-Type" = "application/json" "X-Version" = 3 } $url = "https://$AccountName.logicmonitor.com/santaba/rest$resourcePath" $response = Invoke-RestMethod -Uri $url -Method $httpVerb -Header $headers -ErrorAction Stop $resposne And JavaScript looks like this (at the moment): var ACCESS_ID = 'abc'; var ACCESS_KEY = '123'; var ACCOUNT_NAME = 'portalname'; var resourcePath = '/device/devices'; var time = new Date().getTime(); var epoch = Math.round((time - new Date("1/1/1970").getTime())); var id = 2; var requestVars = 'GET' + epoch + resourcePath; // Compute the HMACSHA256 hash using GlideDigest var gd = new GlideDigest(); var signature = gd.getSHA256Base64(ACCESS_KEY, requestVars); // Remove hyphens from the signature signature = signature.replace(/-/g, ''); var token = 'LMv1 ' + ACCESS_ID + ':' + signature + ':' + epoch; var httpRequest = new GlideHTTPRequest('https://' + ACCOUNT_NAME + '.logicmonitor.com/santaba/rest/device/devices/' + id); httpRequest.addHeader('Content-Type', 'application/json'); httpRequest.addHeader('Authorization', token); httpRequest.addHeader('X-Version', '3'); var response = httpRequest.get(); gs.info('Response status code: ' + response.getStatusCode()); gs.info('Devices = ' + response.body); Anyone know how to make this authentication work, without the customerconvertByteArrayToHex() utility?Solved299Views10likes7CommentsUnable to authenticate Rest api with servicenow to get devices
Hi All, I am trying to authenticate in servicenow using script but it is not working. It is throwing an error authentication failed status 401. var ACCESS_ID = '123'; var ACCESS_KEY = 'abc'; var ACCOUNT_NAME = 'test'; var resourcePath = '/device/devices'; var epoch = (new Date()).getTime(); var id = 2; var requestVars = 'GET' + epoch + resourcePath; var HexUtil = { convertByteArrayToHex : function(byteArray) { var hex = ""; byteArray.forEach(function(byteValue) { hex += HexUtil.convertByteToHex(byteValue); }); return hex; }, convertByteToHex : function(b) { var hexChar = ["0", "1", "2", "3", "4", "5", "6", "7","8", "9", "a", "b", "c", "d", "e", "f"]; return hexChar[(b >> 4) & 0x0f] + hexChar[b & 0x0f]; } }; // Compute the HMACSHA256 hash using GlideDigest var key = "key"; key = encodeURIComponent(key); key = GlideStringUtil.base64Encode(key); var msg = "message"; msg = encodeURIComponent(msg); var mac = new GlideCertificateEncryption(); signature = mac.generateMac(requestVars, "HmacSHA256", ACCESS_ID); var bytes = GlideStringUtil.base64DecodeAsBytes(signature); var hex = HexUtil.convertByteArrayToHex(bytes); var hexB64 = GlideStringUtil.base64Encode(hex); var token = 'LMv1 ' + ACCESS_ID + ':' + signature + ':' + epoch; gs.info('Devices = ' +token); var httpRequest = new GlideHTTPRequest('https://' + ACCOUNT_NAME + '.logicmonitor.com/santaba/rest/device/devices'); httpRequest.addHeader('Content-Type', 'application/json'); httpRequest.addHeader('Authorization', token); //httpRequest.addHeader('x-server-version', '3'); var response = httpRequest.getBody(); gs.log(response); Could you please help me on this.252Views4likes3Commentsstring filters in the API (groovy)
In the past I have not had much need of filters in API, and on the rare occasion I have, it has been numeric filters. But for some reason I cannot get string filters to work at all without throwing errors, either 400 responses, or else unexpected character errors. I can do this all day and get results: queryParams = '?offset=' + offset.toString() + '&size=1000&filter=id:1256'; But as soon as I try to make my filter a string filter, I get errors, and I’ve seen both of the following used in various LM docs online, as if they would work, but I just get unexpected string errors: queryParams = '?offset=' + offset.toString() + '&size=1000&filter=status:active'; queryParams = '?offset=' + offset.toString() + '&size=1000&filter=status:”active”'; Basically, I’m pretty sure I’m just not passing in the string value I want for status in a correct way. I’ve literally seen LM documentation of status:active and I’ve seen other examples when they do name~”whatever” but both of these throw errors. I can even test for status being a number (which obviously give no results), and with no filter, I get back everything (I’m doing setting/admins). And I’ve tried every permutation of quotes in double quotes or backslashed quotes or double and triple quotes and double quotes. Because it something NEWBIE-ish I’m doing wrong. When building a url for the API in groovy, is there some specific way to quote up a string value on a filter? //build the request URL resourcePath = "/setting/admins"; //queryParams = "?size=1000&offset=" + offset.toString(); //queryParams = '?offset=' + offset.toString() + '&size=1000&filter=id:1256'; //queryParams = '?offset=' + offset.toString() + '&size=1000&filter=status:1256'; queryParams = '?offset=' + offset.toString() + '&size=1000&filter=status:active'; queryParams = '?offset=' + offset.toString() + '&size=1000&filter=status:”active”'; url = "https://" + account +".logicmonitor.com/santaba/rest" + resourcePath + queryParams; The first 3 commented items work fine (tho the 3rd one has no results obviously because 1256 isnt a valid status) but as soon as I try status:active or status:”active” its game over. What newbie thing am I doing wrong? Thanks in advance. Cheers!Solved220Views2likes7Commentsauthentication failing in ServiceNow getting error 1401
Hi Team, I trying to get the devices from the logicmonitor into servicenow, it is throwing an error authentication failed. {"data":null,"errmsg":"Authentication failed","status":1401} I have compared postman and token and below script token everything is perfect. Below is the script. can you please help me where is the mistake. var ACCESS_ID = 'test'; var ACCESS_KEY = 'abc'; var ACCOUNT_NAME = 'cde'; var epoch = (new Date()).getTime(); var id = 2; var resourcePath = '/device/devices'; var data= ''; var requestVars = 'GET' + epoch + resourcePath; var HexUtil = { convertByteArrayToHex : function(byteArray) { var hex = ""; byteArray.forEach(function(byteValue) { hex += HexUtil.convertByteToHex(byteValue); }); return hex; }, convertByteToHex : function(b) { var hexChar = ["0", "1", "2", "3", "4", "5", "6", "7","8", "9", "a", "b", "c", "d", "e", "f"]; return hexChar[(b >> 4) & 0x0f] + hexChar[b & 0x0f]; } }; var key = "lma_Bmz]H_625^5H[EQi9U627pdg}8yy(-56X-hsiL7~e^s)9~56ee+^Mh)i3DKXLODZmNTRhNTUtMDM2MC00ZTY5LTkyNWItZGIwNjZmMDMyZTg5L4kmWbA"; key = encodeURIComponent(key); key = GlideStringUtil.base64Encode(key); var msg = requestVars; msg = encodeURIComponent(msg); var mac = new GlideCertificateEncryption(); signature = mac.generateMac(key, "HmacSHA256", msg); gs.print(signature); // Yes! bp7ym3X//Ft6uuUn1Y/a2y/kLnIZARl2kXNDBl9Y7Uo= var bytes = GlideStringUtil.base64DecodeAsBytes(signature); gs.print(JSON.stringify(bytes)); gs.print(bytes.length); // Yes! [110,-98,-14,-101,117,-1,-4,91,122,-70,-27,39,-43,-113,-38,-37,47,-28,46,114,25,1,25,118,-111,115,67,6,95,88,-19,74] var hex = HexUtil.convertByteArrayToHex(bytes); gs.print(hex); // Yes! 6e9ef29b75fffc5b7abae527d58fdadb2fe42e7219011976917343065f58ed4a var hexB64 = GlideStringUtil.base64Encode(hex); gs.print(hexB64); var token = 'LMv1 ' + ACCESS_ID + ':' + hexB64 + ':' + epoch; gs.info('Devices = ' +token); var request = new sn_ws.RESTMessageV2(); request.setEndpoint('https://cde.logicmonitor.com/santaba/rest/device/devices'); request.setHttpMethod('GET'); request.setRequestHeader('Authorization', token); //request.setRequestHeader("Accept", "application/json"); request.setRequestHeader("Content-Type", 'application/json'); var response = request.execute(); var responseBody = response.getBody(); var httpStatus = response.getStatusCode(); gs.log("test==="+httpStatus+responseBody); if (httpStatus == 200) { var temJson = JSON.parse(responseBody); var aTA = temJson.data; gs.log("aTA ==="+aTA); } Thank You, Sai.Solved200Views4likes1CommentWindows Services Monitoring with quite a bit more Automation applied
So today we use LM's Microsoft Windows ServicesDataSource to monitor Windows Services. This DS uses Groovy Script and WMI calls under the hood to fetch the service metrics like state, start mode, status, etc... Everything works fine but one of the prerequisites is to go and manually populate the list of Windows services which then the DS parses out as a WILDVALUE variable in the script. You know, go to the device, click on Down Arrow (Manage Resource Options) --> Add Additional Monitoring --> and CHOOSE from the list of Windows Services. Rinse and Repeat and Save. Then the DS goes to work. Well, what if you have a list of over 100 Windows Services you need to add to let's say 20 Windows devices? That would take forever to populate that list manually... That's a problem number 1. Scratch that. This is not really a problem since one can run a PowerShell script (or Groovy Script) to perform this task using undocumented - but working very well - LM API calls. That problem is solved. Next - This list of over 100 Services needs to be *refreshed* every let's say 24 hours to remove nonexistent services and add new ones based on the Regex filter. That's a problem number 2. And again, one can do it programmatically running API calls but this is where I am trying to figure out how to do it. Run my script as a custom PropertySource? I am not really writing Resource Properties, I am updating instance list (Windows Services) within Additional Monitoring on bunch of Resources. Plus PropertySources are applied when ActiveDiscovery is run which is what, every 24 hours? Or should I write custom DataSource that would accomplish this refresh and specify 1 day collection period? Thanks.Solved199Views4likes2CommentsGetting Graph Sharing Token via REST API
Hello, I am new member of LogicMonior. I have created new dashboard and done aboutadding device graph into dashboard via API, it work! but now, I want to generate “Widget Embedded URL”and also get“Sharing Token” via REST API, after created graph on Dashboard. Is it possible to do that? Thank you very much for all recommendation and commentSolved122Views24likes14CommentsAPI issue with /alert/alerts/ query
So I have been trying to work with the API to get a list of alerts with various bits of data for inclusion in our internal reporting portals and other systems and according to documentation I should be able to get information like the detailMessage from the full list of alerts as well as custom fields that we have created to return data from our ticketing system from the /alert/alerts return, however this does not appear to be the case: I have included the structure of the query and the headers below showing version that we are requesting, the query and URL structure and some examples of the returned data Key Value --- ----- Authorization LMv1 XXXXXXXXXXXXXXXXXXXXX:XXXXXXXXXXXXXXX Content-Type application/json X-Version 3 URL https://XXXXXXX.logicmonitor.com/santaba/rest/alert/alerts?fields=id,sdted,cleared,detailMessage,monitorObjectId,type,monitorObjectName,internalId,acked,severity&size=1000&sort=id&filter=startEpoch>:1675074752 queryString fields=id,sdted,cleared,detailMessage,monitorObjectId,type,monitorObjectName,internalId,acked,severity&size=1000&sort=id&filter=startEpoch>:1675074752 Returned data example: severity : 2 sdted : True monitorObjectName : XXXXXXX-XXX internalId :XXXXXXXXXX monitorObjectId : 770 id : XXXXXXXXX type : dataSourceAlert cleared : False acked : False severity : 2 sdted : True monitorObjectName : XXXXXXX-XXX internalId : XXXXXXXXX monitorObjectId : 770 id : XXXXXXXXX type : dataSourceAlert cleared : False acked : False109Views1like4Comments