[ZBXNEXT-1136] Remove disabled/inactive auto-registered hosts automatically Created: 2012 Mar 01  Updated: 2018 Dec 25

Status: Reopened
Project: ZABBIX FEATURE REQUESTS
Component/s: Server (S)
Affects Version/s: 1.8.10
Fix Version/s: None

Type: Change Request Priority: Major
Reporter: Kleber Vinicius de Carvalho Domingues Assignee: Alexei Vladishev
Resolution: Unresolved Votes: 14
Labels: actions, autoregistration
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

OS Centos 5.7 64bits
DB Postgres 9.0


Issue Links:
Duplicate
is duplicated by ZBXNEXT-2609 Easier auto remove of retired hosts Closed

 Description   

I'm trying to find something to automate the deletion of my disabled hosts on my Zabbix Server.
Soma Action that delete inactive/disabled hosts after a certain time. Do you know somwthing that can be used in this issue?



 Comments   
Comment by richlv [ 2012 Mar 01 ]

what's your definition of "inactive" ?

Comment by Kleber Vinicius de Carvalho Domingues [ 2012 Mar 01 ]

Hosts that are some time without answering Zabbix Server requests. This is the opposite of Auto Discovery.

Comment by Oleksii Zagorskyi [ 2012 Mar 02 ]

"Remove host" operation is available for Discovery's actions.
Probably it should help.

Comment by richlv [ 2012 Mar 11 ]

as mentioned, if you are using network discovery, you can use host removal operation;
if you want to do that based on triggers only, you can run a script and deal with hosts via the api.

i don't think there's going to be anything more specific implemented -> closing

Comment by Oleksii Zagorskyi [ 2013 Jun 04 ]

I updated this feature request summary to reflect a main target - auto-registered hosts automatic removal.

Comment by Oleksii Zagorskyi [ 2013 Jun 04 ]

Any nice ideas how it could be nicely implemented are welcome
Just to discuss it.

Comment by Rob Langley [ 2013 Sep 08 ]

I'm currently using Auto Registration for load balanced servers I'm starting and stopping with Amazon's AWS auto scaling feature. So what would be useful is an operation to Disable Host after xx mins, then 'Delete Host' after xxx mins

For example when the server is terminated it could be disabled after 60 mins, then deleted after 240 mins.

Comment by Ionut Cadariu [ 2015 Mar 28 ]

@Rob, If you have found a way to deal with that type of issues please respond since I'm looking for a way to automatically remove hosts that are no longer available from zabbix.

Thank you

Comment by TonyFu [ 2015 Apr 14 ]

@Ionut Cadariu, I've rencently write a script with python to delete unactive hosts periodly. Call for zbx json-rpc with groupid, we get the status of hosts, then we can decide disable them after specific time and delete them. My zabbix version is 2.2.4, if you're interested, post an email:[email protected] to me.

Comment by JamesH [ 2015 Apr 14 ]

I'm using zabbix_sender called from the zabbix_agent init script upon shutdown to trigger a server-side API call which disables the host. Then a server-side script runs periodically and deletes disabled hosts greater than X days old through the API. It's working for us but I'd like to see this functionality built-in as ephemeral hosts is becoming more widespread.

Comment by Matt [ 2015 Jun 24 ]

@James Hammett

What is the syntax to send the disable signal for zabbix_sender??? I've been searching Google for the past 1.5 hours trying to find exactly that key and value and the best I've found is your comment saying you've done it...

PLEASE reply. PLEASE.

M.

Comment by JamesH [ 2015 Jun 26 ]

Google is no help as I haven't seen anyone else tackle this problem. I created an item named "disable-host" and I have zabbix_sender send the name of the host to it upon shutdown. I created a trigger that triggers upon each update of "disable-host". That triggers an action that runs a server-side script that hits the API disabling the host. Lots of moving parts but 100% reliable so far. Right now I'm working toward making this all work with Docker containers :^)

Comment by richlv [ 2015 Jun 26 ]

please consider using https://www.zabbix.org/wiki/Getting_help for discussion, and maybe even writing a howto on zabbix.org

Comment by Matt [ 2015 Jun 26 ]

@JamesH

Man, thank you. I am totally following what you are saying and am working on a Proof of Concept. I had gotten another idea working just late yesterday.

1) Wrote a "service": /etc/init.d/zabbix-disable-host
2) It phones home:

  • An "enable" at system boot
  • A "disable" at system shutdown
  • (also handles "status" which just queries the Zabbix front end for current status)
    3) The back end of it is a python script on the node itself.

I decided on this way because if the node crashes and burns, it never sends the "disable" back so it will go unreachable (and in turn sound the alert)

Currently, I'm trying to figure out how to get the date/time out of Zabbix when the node went disabled. This way we can retain usage history for the node for X days, then delete it. We don't want it deleted right away. Looking at the API docs, I don't see that Zabbix actually stores anywhere WHEN the node got / went disabled. :-\

M.

Comment by Matt [ 2015 Jun 30 ]

As a small follow up, it doesn't seem that Zabbix records the date/time a node was disabled.

So what I do now in my "service" file (/etc/init.d/zabbix-disable-host) on stop:

  • Sends the "disable (this) host" to Zabbix
    zapi.host.update(hostid=HOSTID, status=new_status)
  • Enables inventory in manual mode (so it doesn't try to populate it in "automatic mode" when we don't care)
    zapi.host.update(hostid=HOSTID,inventory_mode=0)
  • Writes an epoch stamp to "date_hw_decomm" (Date HW decommissioned)
    zapi.host.update(hostid=HOSTID,inventory={'date_hw_decomm': EPOCH})

Server side I scheduled a daily script to:

  • Check that specific inventory key of all disabled hosts
    for h in zapi.host.getobjects(status=1):
       host_id = h['hostid']
       result = zapi.host.get(
         withInventory=1,
         output=["date_hw_decomm"],
         hostids=host_id,
         selectInventory=["date_hw_decomm"])
    
    (after a little monkeying with the json back from Zabbix) you get the epoch stamp recorded when the node was disabled above.
    
    Whip a little math around comparing that stamp to "now" and get a "diff" (number days between "now" and "disabled date").
    
    
  • Whack hosts that were "decommissioned" greater than X days ago.

M.

Comment by richlv [ 2017 Jan 02 ]

might be solvable by ZBXNEXT-1387

Generated at Fri May 09 07:23:49 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.