Getting Datapoint data via REST API
I've been trying to get data for individual datapoints within a single instance datasource via the REST API, in this case there are ~twenty datapoints and I only want data for one of them. Using get_data:https://www.logicmonitor.com/support/rest-api-developers-guide/data/get-data/ I can pick out my datasource, however I can't find any information on filtering by datapoint. When I get data, the datapoints are all listed in an array, then the data is presented as an array of arrays for the last hour...Icould get the position of the datapoint in the first array, then pick out the data using that position for each array listed in the data but that feels like a bad road to travel. query is essentially: "resourcePath = '/device/devices/73023/devicedatasources/1573061/instances/1928726/data'" Right now I'm adding the datapoints I want to a custom graph, I can then pull out the data for that custom graph e.g. "resourcePath = '/device/devices/73023/devicedatasources/1573061/instances/1928726/graphs/3133/data'" (with multiple lines I can pick specific data by checking the line label). Although this works fine, it still feel like an additional step. What I'd really like is: "resourcePath = '/device/devices/73023/devicedatasources/1573061/instances/1928726/ [datapoint/datapointID] /data'" but I can't see an ID for datapoints or an option for putting a 'name' in. Have I missed something? Does anyone already do this in a simple way?Solved73Views0likes11CommentsAdd device to Collector with least devices in rest api
I hope someone here can help, Using powershell and the rest API I would like to do a lookup of selected collectors find which has the least amount of devices on it then add the a new device. I have the script for adding the device and that works greatjust need the collector lookup, has anyone done something similar. Thank you in advanced for all help provided PaulSolved37Views0likes49CommentsImport Datasource via API and PowerShell
Hello All, I'm attempting to import datasources into our LogicMonitor instance, using the API and PowerShell. The following documentation only provides a CURL example, which isn't really sufficient for us. https://www.logicmonitor.com/support/rest-api-developers-guide/datasources/import-datasources-from-xml/ Usage: Import-LMDatasource -Credential $credentials -FilePath 'c:\repositories\LogicModules\DataSources\CustomDataSource.xml' I am assuming that you have an array containing your accessId, accessKey and company name, prior to calling the function. The parameter FilePath is the full path to the XML file to be uploaded. function Import-LMDatasource { [CmdletBinding()] param ( [Parameter(Mandatory = $false)] [array]$Credential, [Parameter(Mandatory = $false)] [ValidateNotNullOrEmpty()] [string]$FilePath ) Begin { if(-not($Credential)) { $accessId = Read-Host -Prompt "Please supply accessId:" $accessKey = Read-Host -Prompt "Please supply accessKey:" $company = Read-Host -Prompt "Please supply company:" } else { $accessId = $Credential.accessId $accessKey = $Credential.accessKey $company = $Credential.company } $httpVerb = 'POST' $resourcePath = '/setting/datasources' $queryParams = '/importxml' $data = '' $url = 'https://' + $company + '.logicmonitor.com/santaba/rest' + $resourcePath + $queryParams $epoch = [Math]::Round((New-TimeSpan -Start (Get-Date -Date '1/1/1970') -End (Get-Date).ToUniversalTime()).TotalMilliseconds) $contentType = [System.Web.MimeMapping]::GetMimeMapping($FilePath) } Process { $requestVars = $httpVerb + $epoch + $data + $resourcePath $hmac = New-Object System.Security.Cryptography.HMACSHA256 $hmac.Key = [Text.Encoding]::UTF8.GetBytes($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())) $auth = 'LMv1 ' + $accessId + ':' + $signature + ':' + $epoch Add-Type -AssemblyName System.Net.Http $httpClientHandler = New-Object System.Net.Http.HttpClientHandler $httpClient = New-Object System.Net.Http.HttpClient $httpClientHandler $httpClient.DefaultRequestHeaders.Authorization = $auth $packageFileStream = New-Object System.IO.FileStream @($filePath, [System.IO.FileMode]::Open) $contentDispositionHeaderValue = New-Object System.Net.Http.Headers.ContentDispositionHeaderValue 'form-data' $contentDispositionHeaderValue.Name = 'file' $contentDispositionHeaderValue.FileName = (Split-Path -Path $FilePath -Leaf) $streamContent = New-Object System.Net.Http.StreamContent $packageFileStream $streamContent.Headers.ContentDisposition = $contentDispositionHeaderValue $streamContent.Headers.ContentType = New-Object System.Net.Http.Headers.MediaTypeHeaderValue $contentType $content = New-Object System.Net.Http.MultipartFormDataContent $content.Add($streamContent) $response = $httpClient.PostAsync($url, $content).Result if(!$response.IsSuccessStatusCode) { $responseBody = $response.Content.ReadAsStringAsync().Reult $errorMessage = "Status code {0}. Reason {1}. Server reported the following message: {2}." -f $response.StatusCode, $response.ReasonPhrase, $responseBody throw [System.Net.Http.HttpRequestException] $errorMessage } return $response.Content.ReadAsStringAsync().Result # $httpClient.Dispose() # $response.Dispose() } End { } } Result: {"errmsg":"Request content is too large, max allowed size is 10240","status":1007} Dot Sourcing the function at runtime allows me to inspect the variables set during execution: $response Version : 1.1 Content : System.Net.Http.StreamContent StatusCode : OK ReasonPhrase : OK Headers : {[Date, System.String[]], [Server, System.String[]]} RequestMessage : Method: POST, RequestUri: 'https://<instance>.logicmonitor.com/santaba/rest/setting/datasources/importxml', Version: 1.1, Content: System.Net.Http.MultipartFormDataContent, Headers: { Authorization: LMv1 <ACCESSTOKEN-OBFUSCATED> Content-Type: multipart/form-data; boundary="17ba48f6-b5e9-48c6-9002-7544d99025d8" Content-Length: 11858 } IsSuccessStatusCode : True Uploading the exact same datasource XML via the GUI works. I think I'm most of the way there, but obviously something I'm doing is bloating the request size and tripping this limit. Has anyone had any success with uploading datasources via the API? Many Thanks, ~Nick23Views0likes4CommentsAPI call, get ALL devices
Hi, I have a teammate working on some API calls to help us manage our environment a bit better. One thing he noted is that LM doesn't allow us to make a single API call which returns all devices? Wanted to see if there was a way to accomplish this, or if this is a limitation that's going to be lifted? Thanks, Eric21Views0likes3CommentsCreate role for API only user
Problem I havea datasource that collects information from the LogicMonitor API. In order for this to work correctly I need a valid user on the LM platform with a valid API token. I can see two potential paths forward. Case 1 - Use my existing account as the datasource author with my API token. This has a big downside that if I have to leave the company for any number of reasons and my account gets disabled this datasource will stop working and is customer facing. This is probably not so good. Case 2 - Create a 'service account' inside LogicMonitor that can have its' own API token and if any one human needs to leave the company there really is not a big problem. The issue with this is that this user has a username and a password that can grant it access to the UI under all the permissions granted by the role but this account should/will never be used within the UI. This also generates a potential securityproblem because the password will most likely never be rotated because as long as the API user and token work this is simply going to sit there. Request Be able to create a new user type of 'API only' which will never have access to the UI and therefore you should not have to set any of the UI specific information for the account. This would remove the need for any of this information under that account: First/Last name/Email/Password/Force password change/2-factor/Phone/SMS/SMS Email format19Views1like3CommentsAdd device to group API
I'm trying to find the right way to add an existing device to an existing group via the REST API. I've tried PATCHing / PUTing the hostGroupIds field of the device but that doesnt work, and I get the following. "errmsg" : "Property(name=hostGroupIds) cannot be found in device(id=1504)'s own property" Should I add the group ID to the device, or can I edit the devices in a Group via the API?18Views0likes2CommentsLogicMonitor Integration with IFTTT (If This, Then That)
IFTTT is a free SaaS platform that helps you "do more with all your apps and devices" - by providing an integration point betweencommonly used services and platforms. In the following example, we're using the IFTTT Applet webhooks "trigger" to activate a Philips Hue wireless lighting "action" - blinking the lights of the connected Hue platform as a result ofa LogicMonitor alert! Other things you might be able to do with LogicMonitor alerts, through IFTTT (lots of untested possibilities!) : Change lighting colors based on alert status (red for new, green for cleared, etc.) Receive alert notificationsto connected systems like Skype,Twitter, Evernote, or Google. Play music on a connected Sonos system after triggering an alert. Turn on a connected Smart Plug like the Wemo from Belkin. The Finished Result The following tutorial assumes that you have an IFTTT account created and permissions to add an integration to your LogicMonitor account. Step 1: Log into your IFTTT account and create a new 'Applet' Step 2: Search for and choose the 'Webhooks' service. Step 3: Choose the 'Receive a Web Request' trigger. Step 4: Configure (and remember) the event name that will be recognized by the incoming webhook to trigger the event. Step 5: Configure the 'Action' that will be taken when this event is triggered in IFTTT - lots of intriguing possibilities! Step 6: Once you've added and configured the 'Action,' review the applet settings and click 'Finish' to save the Applet. Step 7: Select 'Services' from the account dropdown - we will be looking up the incoming webhook URL for our account so we know where to send our alerts. Step 8: Search for the 'Webhooks' service and select it to proceed. Step 9: Select the 'Documentation' link from the 'Webhooks' services page. Step 10: Copy the incoming Event trigger URL along with the key for your account. You will replace {event} in the URL with the one you configured above. Step 11: Moving to your LogicMonitor account, navigate to 'Settings -> Integrations' and add a new 'Custom HTTP Delivery' integration using the event name from Step 4 and theURL (with key) from Step 10 : Step 12: IFTTT allows you to include an (optional!) payload - which will show in the 'Activity Log' of the IFTTT Applet. Step 13: Test Alert Delivery and you should see output similar to below in the IFTTT Activity Log. Step 14:Save your integration, assign it to an Escalation Chain, and assign the Escalation Chain to an Alert Rule - and now we've configured a simple integration between LogicMonitor and IFTTT that could form the basis of a handful of interesting alert actions!13Views0likes1CommentHTTP Authentication Required?
I have two sets of code. 1 pulls all 'Services' or Website groups. The other is supposed to just pull the group name and id. The first works, the second doesn't. I am using the base PowerShell script laid out in the documentation. If I remove the ?fields=name,id it works without issue. If I add it back it gives me this error "HTTP Status 401 - Unauthorizedtype Status reportmessage Unauthorizeddescription This request requires HTTP authentication.LogicMonitor Technical Operations". Any help would be awesome. <# request details #> $httpVerb = 'GET' $resourcePath = '/service/groups?fields=name,id' $status = $null $body = $null $response = $null <# Construct URL #> $url = 'https://' + $company + '.logicmonitor.com/santaba/rest' + $resourcePathSolved11Views0likes2CommentsAPI - Posting widget updates via powershell
Hello, Trying to get the below script to work, but hitting a snag. I've tried to repurpose the DataSource Upload Example script from this page to get the desired result but no dice. Param([Parameter(Mandatory=$true)][string]$name,[string]$GetInstance,[string]$GetType,[string]$Computername)<# Use TLS 1.2 #>[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $accessId = '###'$accessKey = '###'$company = '###'$httpVerb = 'PUT'$widgetID = "350"$resourcePath = "/dashboard/widgets/$widgetID"$queryParams = ''$boundary = [System.Guid]::NewGuid().ToString()$LF = "\r\n"$data = @" "items":[{"deviceGroupFullPath":"*","deviceDisplayName":"$computername","dataSourceDisplayName":"$name","instanceName":"$Name","dataPointName":"FolderGT60","groupBy":"instance","name":"$getinstance"}]"@$url = 'https://' + $company + '.logicmonitor.com/santaba/rest' + $resourcePath + $queryParams$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($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()))$auth = 'LMv1 ' + $accessId + ':' + $signature + ':' + $epoch$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"$headers.Add("Authorization",$auth)$headers.Add("Content-Type","multipart/form-data; boundary=----$boundary")$response = Invoke-RestMethod -Uri $url -Method $httpVerb -body $data -Header $headers $status = $response.status$body = $response.dataWrite-Host "Status:$status"Write-Host "Response:$body" I assume that the '$headers.Add("Content-Type","multipart/form-data; boundary=----$boundary")' section, or '$boundary', is incorrect but have only really been looking into anything Logicmonitor-API-Powershell in the last 24 hours. I'm getting HTTP 415 error Unsupported Media Typeh1 which I thought originally was from the $data section but I can't figure out any other way to pass the JSON into the variable. Thanks, Amir.10Views0likes2CommentsAPI - Add Instance Count as Datasource Property
I'm trying to clean up datasources that are in our account that do not have any instances associated with them and likely never will. Currently I have to do this manually by inspecting each datasource in the GUI. It would be really great if the datasource instance count was returned as a property. Even better would be if the instances and associated device ID's were returned as well, but for now I'd be happy with just the device/instance counts.10Views0likes4Comments