![]() |
![]() |
Subject: | Zenoss API, Curl to PowerShell |
Author: | [Not Specified] |
Posted: | 2015-03-16 09:56 |
I saw someone, who I can't find now, that said they were taking curl commands and porting them into PowerShell. I am wondering if someone can give me some examples of working PowerShell commands that I can use to get things like a list of servers, or change the status of a server (from Production 1000 to Maintenance 300).
Invoke-RestMethod -Uri 'http://servername.dom.com:8080/zport/dmd/Devices/Server/Linux/devices/se... -Method Post -Credential $credential2
It looks like a bunch of HTML output, I sure would like to figure out how to get this working.
Subject: | #global variables for |
Author: | [Not Specified] |
Posted: | 2015-03-18 12:22 |
#global variables for configuration
$ZENBASE = "http://zenoss.yourdomain.com";
$ZAPIUSER= "username";
$ZAPIPASS = "password";
Function zWinPost
{
param($ROUTER_ENDPOINT, $ROUTER_ACTION, $ROUTER_METHOD, $DATA);
$DATA='['+$DATA+']'
$json = '{"action": "' + $ROUTER_ACTION + '","method": "' + $ROUTER_METHOD + '","data":' + $DATA + ', "tid":1}'
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $ZAPIUSER,$ZAPIPASS)))
$output = Invoke-RestMethod -Uri "$ZENBASE/zport/dmd/$ROUTER_ENDPOINT" -Method Post -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Body $json
return $output
}
Function zWinGetDevices
{
$ROUTER_ENDPOINT = "device_router"
$ROUTER_ACTION = "DeviceRouter"
$ROUTER_METHOD = "getDevices"
$DATA = '{}'
$devJSON = zWinPost $ROUTER_ENDPOINT $ROUTER_ACTION $ROUTER_METHOD $DATA
$devJSON.result.devices
}
If you wanted to get just the names of the devices, you would change $devJSON.results.devices to $devJSON.results.devices.name etc.
The -Credential flag only works with challenge authentication. With Zenoss, you send the authentication credentials at the same time as the json
Subject: | I just answered my own |
Author: | [Not Specified] |
Posted: | 2015-07-27 19:05 |
I just answered my own question.
Set $DATA with the parameter and value:
$DATA = '{"limit":500}'
Subject: | I just answered my own |
Author: | [Not Specified] |
Posted: | 2015-07-27 20:12 |
Trying to figure out how to supply a params for a name to lookup. Can anyone help
Attempted variations of this, but does not work.
$DATA = '{"limit":5000,"params":"name.key[$name]"}'
Subject: | It should be: |
Author: | Jan Garaj |
Posted: | 2015-07-28 01:10 |
It should be:
$DATA = '{"limit":5000,"params":{"name": $name}}'
Devops Monitoring Expert advice:
Dockerize/automate/monitor all the things.
DevOps stack:
Docker / Kubernetes / Mesos / Zabbix / Zenoss / Grafana / Puppet / Ansible / Vagrant / Terraform /
Elasticsearch
Subject: | maintenance state return |
Author: | [Not Specified] |
Posted: | 2015-07-31 15:07 |
Just curious, how would this work if I wanted to return devices under maintenance prodState
$DATA = '{"limit":1000,"params":{"prodState": "Maintenance"}}'
I've tried both the above and the numerical value associated with Maintenance state.
Any Ideas
Subject: | Check how it works in UI and |
Author: | Jan Garaj |
Posted: | 2015-07-31 18:13 |
Check how it works in UI and then you will be able to construct your own filter - http://i.imgur.com/l4kiepS.png
=> $DATA = '{"limit":1000,"params":{"productionState": [300]}}'
Devops Monitoring Expert advice:
Dockerize/automate/monitor all the things.
DevOps stack:
Docker / Kubernetes / Mesos / Zabbix / Zenoss / Grafana / Puppet / Ansible / Vagrant / Terraform /
Elasticsearch
< |
Previous Monitor wan services |
Next Graphing snmp strings such as "0.20 %" |
> |