The following are useful examples that show you how to get started.
For more complex use, see the scripts in examples dir.
- Get metrics
- Return just one result
- Export users by userid
- Use a different config file
- Use a filter with a space in the VALUE
- Pipe stdout to another program
- Find all hosts in a group by name
- Write data to a file
- Hostgroup and Collector Group don't match
- Add header and footer custom text
- Filter by customProperties, systemProperties, autoProperties etc
- Find all the values for a custom property
- Find all the devices belonging to a static group
- Find all the devices belonging to a dynamic group
- Find all groups that have a customProperty set
- List collector build versions
- Find long SDTs
- Find non-auto balanced devices on a collector
- Compare devices in two groups
- Find Collector Groups that have more than 1 collector but not autobalanced
- Dashboards
- Reports
- meta
A simple query to get usage metrics and show them in formatted json:
./elm -f prettyjson MetricsUsage
{
"MetricsUsage": [
{
"numOfAWSDevices": 16,
"numOfAzureDevices": 6,
"numOfCombinedAWSDevices": 8,
"numOfCombinedAzureDevices": 12,
"numOfCombinedGcpDevices": 0,
"numOfConfigSourceDevices": 0,
"numOfGcpDevices": 0,
"numOfServices": 0,
"numOfStoppedAWSDevices": 10,
"numOfStoppedAzureDevices": 0,
"numOfStoppedGcpDevices": 0,
"numOfTerminatedAWSDevices": 6,
"numOfTerminatedAzureDevices": 0,
"numOfTerminatedGcpCloudDevices": 0,
"numOfWebsites": 3,
"numberOfDevices": 126,
"numberOfKubernetesDevices": 148,
"numberOfStandardDevices": 106
}
]
}
Use the -s
flag to limit the results returned:
./elm DeviceList -s1
note: setting size to 0 will return all results (up to 1000)
Show the id and username for users with id between 2 and 5, sort by reverse username, and put in csv format:
./elm -f csv AdminList -f id,username -S -username -F id\>:2,id\<:5
You can have more than one config file. This is handy if you have multiple API keys or accounts and want to switch between them:
./elm --config ~/.elm/dev.ini MetricsUsage
To use space in the VALUE of a filter, you will have to quote the VALUE:
./elm DeviceGroupList -f id,name,description -F name:"group with space"
You can pipe the data to other programs using standard unix pipes. STDOUT is the default option. This example shows passing the data into jinja:
./elm DatasourceById --id 12345678 | \
jinja2 /path/datasource.jira.j2 - | \
pbcopy
This will show all hosts name and display name in the group "Linux Devices":
gid=$(./elm DeviceGroupList -f id -F name:"Linux Devices" | \
jq -r '.DeviceGroupList[].id')
./elm DeviceList -s0 -f name,displayName -F hostGroupIds~${gid} | \
jq -r '.DeviceList[] | [.name, .displayName] | @csv'
In one line:
./elm DeviceList -s0 -f name,displayName -F hostGroupIds~$(./elm DeviceGroupList -f id -F name:"Linux Devices" | \
jq -r '.DeviceGroupList[].id') | jq -r '.DeviceList[] | [.name, .displayName] | @csv'
./elm -o filename MetricsUsage
Useful for matching hosts to collector groups. Assumes you use a similar naming pattern for both hosts and collector groups (eg foo)
Note: the "!" has to be escaped to stop bash interperating it
./elm DeviceList -f name,displayName,preferredCollectorGroupName -F displayName~foo,preferredCollectorGroupName\!~foo
Useful for adding a warning to the top of text that the data is automatically generated, and adding a datestamp to the footer. The example below is in jira markup:
./elm --head "{warning}This information is automatically generated. Changes may be overwritten!{warning}" --foot "_above extracted at $(date "+%Y-%m-%d %H:%M")_" --format jira MetricsUsage
If you want to filter the device list by customProperties, systemProperties, autoProperties etc, filter by X.name and X.value like so:
./elm DeviceList -f customProperties -F customProperties.name:customer.name,customProperties.value:customerA
For caveats, see the comments by David Bond on this post: [Get LM DeviceGroup Properties REST API]
"There is no way to effectively filter by effective property"
If you want to find all the values where the custom property name matches (eg) "wmi.user". This pipes the output to jq which then selects only the matching name and returns it's value from the json output:
On an group level:
./elm -f json DeviceGroupList -F customProperties.name:wmi.user -f customProperties | \
jq -r '.DeviceGroupList[].customProperties[] | select(.name=="wmi.user") | .value' | \
sort -u
Same as above, but for all indidual devices:
./elm -f json DeviceList -F customProperties.name:wmi.user -f customProperties | \
jq -r '.DeviceList[].customProperties[] | select(.name=="wmi.user") | .value' | \
sort -u
Another similar way to do this, but also print the device name
and
displayName
along with the value of a customProperty (in this case
"snmp.security").
The example will find all devices where displayName contains "foo"
and has the "snmp.security" custom property key set, and then output
the "name", "displayName" and the associated custom property value,
outputing it as a tsv seperated values. The tab values are then swapped
for commas before passing to the unix commands sort
and column
.
./elm -f json DeviceList -F displayName~foo,customProperties.name:snmp.security -f name,displayName,customProperties -s0 | \
jq -r --arg name "snmp.security" '.DeviceList[] | .customProperties[] as $custom | select($custom.name==$name) | [.displayName, .name, $custom.value] | @tsv | gsub("\\t";",")' | \
sort | \
column -t -s,
Same as above, but for all groups:
elm -f json DeviceGroupList -F customProperties.name:foo.bar -f name,customProperties -s0 | jq -r --arg name "foo.bar" '.DeviceGroupList[] | .customProperties[] as $custom | select($custom.name==$name) | [.displayName, .name, $custom.value] | @tsv | gsub("\\t";",")' | sort | column -t -s,
Like the custom property above, this solution uses jq to filter the results:
./elm -f json DeviceList -F systemProperties.name:system.staticgroups,systemProperties.value\~"Root/Group/Name/" -f name,displayName,systemProperties -s0 | \
jq -r --arg name "system.staticgroups" '.DeviceList[] | .systemProperties[] as $system | select($system.name==$name) | [.displayName, .name, $system.value] | @csv'
./elm -f json DeviceList -F systemProperties.name:system.groups,systemProperties.value\~"Root/Group/Name/" -f name,displayName,systemProperties -s0 | \
jq -r --arg name "system.groups" '.DeviceList[] | .systemProperties[] as $system | select($system.name==$name) | [.displayName, .name, $system.value] | @csv'
Like the custom property above, this solution uses jq to filter the results:
elm -f json DeviceGroupList -F customProperties.name:ClientID -f name,fullPath,customProperties -s0 | \
jq -r --arg name "ClientID" '.DeviceGroupList[] | .customProperties[] as $custom | select($custom.name==$name) | [.name, .fullPath, $custom.value] | @csv'
Show the collector build version and when it was last update; sorted by build number and updated time:
./elm CollectorList -f hostname,build,updatedOnLocal -S build,updatedOnLocal
This will find SDTs that don't end for at least one year from the current time:
./elm SDTList -F endDateTime\>$(( ( $(date +'%s') + 31536000 ) * 1000 )) -f id,deviceGroupFullPath,deviceDisplayName,endDateTimeOnLocal,duration,admin,comment -S endDateTime -s0
./elm DeviceList -f id,name,displayName,autoBalancedCollectorGroupId,collectorDescription -F collectorDescription\~"DESC_HERE",autoBalancedCollectorGroupId:0 -s0
Find all the devices in two groups and then compare them, showing devices that aren't in both groups:
./elm -f txt -o group_a.txt DeviceList -F systemProperties.name:system.groups,systemProperties.value\~"Root/Group_A" -f displayName -S displayName -s0
./elm -f txt -o group_b.txt DeviceList -F systemProperties.name:system.groups,systemProperties.value\~"Root/Group_B" -f displayName -S displayName -s0
comm -3 group_a.txt group_b.txt
elm -f txt CollectorGroupList -F autoBalance:false,numOfCollectors\>1 -f autoBalance,name,numOfCollectors
This example will show dashboards that use "Root/Group" as their defaultResourceGroup:
elm -f txt DashboardList -s0 -F widgetTokens.name:defaultResourceGroup,widgetTokens.value\~Root/Group -f fullName
This example will show reports that use "Root/Group" as their hostsVal:
elm -f txt ReportList -s0 -F hostsVal\~Root/Group -f name
Update the ToC on this page by running the following:
gh-md-toc --insert --no-backup --skip-header EXAMPLES.md
[Get LM DeviceGroup Properties REST API]: https://community.logicmonitor.com/product-discussions-22/get-lm-devicegroup-properties-rest-api-1473?postid=8985#post8985)