ContributionsMost RecentMost LikesSolutionsRe: Trouble Authenticating to LogicMonitor REST API from ServiceNow I don’t seem to have access to CryptoJS. Trouble 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? SolvedPATCH website custom property via API Anyone have some PowerShell that will update the custom properties of a Website (ping check)? I have been fiddling around and the following code will update properties like name or host (for example), but will not add a custom property. The code runs without error and returns the website as expected, but the change is not reflected in the portal. [string]$AccessId = '' [securestring]$AccessKey = ('' | ConvertTo-SecureString -AsPlainText -Force) [string]$AccountName = '' [int]$Id = '' #website id [hashtable]$PropertyTable = @{ 'propertyName' = 'test' } [string]$httpVerb = 'PATCH' [string]$resourcePath = "/website/websites" $AllProtocols = [System.Net.SecurityProtocolType]'Tls11,Tls12' [System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols $resourcePath += "/$Id" $data = $PropertyTable | ConvertTo-Json -Depth 6 $enc = [System.Text.Encoding]::UTF8 $encdata = $enc.GetBytes($data) $url = "https://$AccountName.logicmonitor.com/santaba/rest$resourcePath" $epoch = [Math]::Round((New-TimeSpan -start (Get-Date -Date "1/1/1970") -end (Get-Date).ToUniversalTime()).TotalMilliseconds) $requestVars = $httpVerb + $epoch + $data + $resourcePath $hmac = New-Object System.Security.Cryptography.HMACSHA256 $hmac.Key = [Text.Encoding]::UTF8.GetBytes([System.Runtime.InteropServices.Marshal]::PtrToStringAuto(([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($AccessKey)))) $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 $accessId`:$signature`:$epoch" "Content-Type" = "application/json" "X-Version" = 3 } $response = Invoke-RestMethod -Uri $url -Method $httpVerb -Header $headers -Body $encdata -ErrorAction Stop $response Re: Is there a way to report on the maximum value per day that a metric reaches? You could also query the API, to retrieve the data, and return only the largest value. Re: PowerShell SDK +1 for mine :)/emoticons/smile@2x.png 2x" title=":)" width="20" /> Incidentally, I published version1.0.1.81 now. Please feel free to contribute viahttps://github.com/wetling23/logicmonitor-posh-module Re: Receiving alert via webhook I do not know enough about webhooks in general, or Cisco's implementation specifically, to know if this is useful. We would need to have Cisco support authentication, right? I'm guessing I couldn't provide an LM API access id and key for authentication. Receiving alert via webhook I would like to alert when Cisco Air Marshal detects a rogue access point and found this Postman workspace,which indicates that Cisco will post to a webhook. I also found a href="https://communities.logicmonitor.com/topic/2146-meraki-webhooks/" rel="">this LM communities postfrom 2018, which does not seem to have been implemented. Am I missing something or will I have to post to some other webhook (maybe Cisco supports Teams or Slack, idk) andwrite some script to query to webhook target (e.g. Teams), looking for the alert message? Re: Trouble with Fortigate PropertySource script Thanks, that seems to have worked. I've published the final version tohttps://github.com/wetling23/Public.LogicMonitorPsScripts/tree/master/PropertySourcesScripts/fortinet. Re: Trouble with Fortigate PropertySource script 3 hours ago, Stuart Weenig said: Like i said, not familiar with that particular method of connecting via SSH. I use JSch or Expect. This seems to be working better (at least I can get back data). Now I am running into a problem adding the VDOMs to a list, which I will (eventually) turn into a property. I am getting the following output: Any idea why, with the code below, I am failing to append "root" and "exit" to the list of VDOMs? importcom.santaba.agent.groovyapi.expect.Expect hostname=hostProps.get("system.hostname") userid=hostProps.get("ssh.user") passwd=hostProps.get("ssh.pass") deflist=newArrayList() try{ ssh_connection=Expect.open(hostname,userid,passwd) ssh_connection.expect("#") ssh_connection.send("configvdom\n") ssh_connection.expect("#") cmd_output=ssh_connection.before() if(cmd_output=~/\(vdom\)/){ println"invdomconfig,runningtheeditcommand" ssh_connection.send("edit?\n") ssh_connection.expect("#") } cmd_output2=ssh_connection.before() println"attemptingtoparsevdoms" cmd_output2.eachLine{line-> if(!(line=~/\<vdom\>/)&&!(line=~/^\s*$/)&&!(line=~"edit")&&!(line=~/\(vdom\)/)){ println"adding"+line+"tothelistofvdoms" list.Add(line) } } ssh_connection.send("\025") ssh_connection.send("exit\n") println"returningvdoms:" printlnlist.join(",") return0 } catch(Exceptione){printlne;return1} finally{if(ssh_connection){ssh_connection.expectClose()}} Re: Trouble with Fortigate PropertySource script Just to be clear, I should add that, once this actually gets the command output, I will want to remove the "<vdom> Virtual Domain Name" lines and return the actual VDOM list as a comma-separated string.
Top ContributionsTrouble Authenticating to LogicMonitor REST API from ServiceNowSolvedPATCH website custom property via APILogicMonitor PowerShell moduleRe: API filter on multiple propertiesAPI filter on multiple propertiesRe: PowerShell SDKRe: Trouble with Fortigate PropertySource scriptRe: API filter on multiple propertiesRe: API filter on multiple propertiesAdditional tokens for alert messages