TECHZEN Zenoss User Community ARCHIVE  

Need a curl based command to delete a device from group

Subject: Need a curl based command to delete a device from group
Author: Anjan Kumar Tripathy
Posted: 2021-03-16 08:59

Hi team,

In relation to automation we have a flow where we need to figure out to which group the list of devices belongs to and then deleting the devices from the respective group.

below command helps identifying the group associated with a devices

curl -k -u "user:password" -X POST -H "Content-Type:application/json" -d "{\"action\":\"DeviceRouter\",\"method\":\"getDevices\",\"data\":[{\"uid\":\"/zport/dmd/Devices\",\"keys\":[\"id\",\"groups\"],\"params\":{\"ipAddress\":\"1.2.3.4\"},\"page\":1,\"start\":0,\"limit\":100,\"sort\":\"name\",\"dir\":\"ASC\"}],\"type\":\"rpc\",\"tid\":14}" "https://zenoss5.nj-rm641.a.zenoss.sup:443/zport/dmd/device_router"
With the following the payload I captured when removing a group from a device:

let Say Server "A" was part of Grp1 & Grp2

Can someone help me with a similar command to get Server A deleted from Grp1 & Grp2.

I am new to Zenoss and struggling with this bit

Regards
ANjan

------------------------------
anjan tripath
Seniour associate
Cognizant
KS
------------------------------


Subject: RE: Need a curl based command to delete a device from group
Author: Michael Rogers
Posted: 2021-03-16 18:30

Anjan,

Here is a sample payload for removing a device ("server-a") from two groups at the same time ("Group1" & "Group2").

[{"action":"DeviceRouter","method":"removeDevices","data":[{"uids":["/zport/dmd/Devices/Server/Linux/devices/server-a"],"hashcheck":"","uid":"/zport/dmd/Groups/Group1"}],"type":"rpc","tid":20},{"action":"DeviceRouter","method":"removeDevices","data":[{"uids":["/zport/dmd/Devices/Server/Linux/devices/server-a"],"hashcheck":"","uid":"/zport/dmd/Groups/Group2"}],"type":"rpc","tid":21}]

If you ever need to find the syntax for an API call, the easiest thing to do is perform the same step through the GUI and watch the network tab in your browsers dev console.

In practice, it would look something like this:

1. Remove server-a from Group1 and Group2 (click both "Remove" buttons, then click "Save"):


2. Find the relevant device_router call (usually the one that isn't using the getInfo method):


3. Switch from "parsed" to "source" so you can see the raw JSON being sent:


Naturally, all the standard cautions apply:

* Test your API calls in a test/dev environment.
* If no test/dev environment are available, test against a dummy device created for the purposes of the test.
* Make sure you have a known-good backup before automating in your production environment.

------------------------------
Michael J. Rogers
Senior Instructor - Zenoss
Austin TX
------------------------------


Subject: RE: Need a curl based command to delete a device from group
Author: Anjan Kumar Tripathy
Posted: 2021-03-19 09:12

Hi Michel,

Thanks for the reply, I tried it out and it worked.

Your tip really helped me a lot to grab the API from network Tab. didnt knew it before it would be of great help

Regards
Anjan

------------------------------
anjan tripath
Seniour associate
Cognizant
KS
------------------------------

Subject: RE: Need a curl based command to delete a device from group
Author: Anjan Kumar Tripathy
Posted: 2021-03-19 10:22

Thanks


< Previous
Need to analyse the Impact of a Payload
  Next
DNS monitoring on 6.x
>