rrg92 / power-zabbix

Powershell module with lot of cmdlets that implements ZABBIX API, extra and auxiliary cmdlets
4 stars 2 forks source link

Implement Remove-ZabbixHost #2

Open lep1986 opened 6 years ago

lep1986 commented 6 years ago

Hi, I'm trying to delete the one host but I'm not doing well. What i'm doing wrong?

Import-module D:\power-zabbix-master\power-zabbix.psm1
 Auth-Zabbix -URL 'http://192.168.137.242/zabbix/' 
 $r = (Get-ZabbixHost -name  server1)
 Remove-ZabbixHostMass -ZabbixHost $r
rrg92 commented 6 years ago

You must pipe result of Get-ZabbixHost to Remove-ZabbixHostMass:

(Get-ZabbixHost -name  server1) | Remove-ZabbixHostMass

But this action don't remove the host. It is used to remove objects from multiple hosts.

We not implemented yet the method "Remove-ZabbixHost". I will add this soon. For a workaround, you can manually build the request:

import-module power-zabbix
Auth-Zabbix -Url 'http://192.168.137.242/zabbix/'

#Get your host!
$MyHost = Get-ZabbixHost -Name server1 -output @('hostid');

#Build the params object to the host.delete
$request = ZabbixAPI_NewParams "host.delete";

#Here, you can include many host host as a arry. Just separare each id, using a comma
$request.params = @($MyHost.hostid);

#Now call the zabbix!
$result =  Invoke-ZabbixURL $request -Translate;

#If not exception throws, then this result will contains the id of hostids deleted.
$result.RawTranslate
rrg92 commented 4 days ago

Hey @SCH48 E @lep1986 , thanks a lot for the feedback. I was on hold for a few years due to career and personal changes. Recently, I saw that this module was officially listed on the Zabbix page, and I believe that because of this, it's worth continuing to evolve it and updating it to support the current versions. I'm making some new commits and will soon give better attention to these issues.