I try to automate the discovery of my entire network, which is managed with puppet, and I want to use the zabbix network discovery feature instead of Puppetdb for mulitple reasons.

I've tried creating a userparameter named puppet.classes which return all classes as a comma separated values (ex: ,apache,mysql,zabbix,). This is called as Checks on the discovery rule.


Then set in my actions "Received value like ,apache," then "Link to templates: Apache". screenshot

Everything is fine with only few puppet classes, but the value is truncated in the database in my test environment:

[zabbix]> select dserviceid,dhostid,status,lastup,lastdown,value,dns from dservices where dcheckid=3 and type=9 and key_='puppet.classes' \G
*************************** 1. row ***************************
dserviceid: 9
   dhostid: 3
    status: 0
    lastup: 1464103581
  lastdown: 0
     value: ,apache,apache::default_confd_files,apache::default_mods,apache::mod::alias,apache::mod::dir,apache::mod::filter,apache::mod::mime,apache::mod::php,apache::mod::prefork,apache::mod::ssl,apache::mod::status,apache::params,apache::service,apache::version,ap

After debugging quite a lot, i've finally found that discovery checks cannot be bigger than 255 bytes in

  static void discovery_update_dservice(zbx_uint64_t dserviceid, int status, int lastup, int lastdown, const char *value)
      char    *value_esc;
      value_esc = DBdyn_escape_string_len(value, DSERVICE_VALUE_LEN);
      DBexecute("update dservices set status=%d,lastup=%d,lastdown=%d,value='%s' where dserviceid=" ZBX_FS_UI64, status, lastup, lastdown, value_esc, dserviceid);


  #define DSERVICE_VALUE_LEN        255`

Using metadata with autoregistration will have the same limitation:

### Option: HostMetadata
#   Optional parameter that defines host metadata.
#   Host metadata is used at host auto-registration process.
#   An agent will issue an error and not start if the value is over limit of 255 characters.
#   If not defined, value will be acquired from HostMetadataItem.
# Mandatory: no
# Range: 0-255 characters
# Default:
# HostMetadata=

I could use the API and write a script that does this by myself, but this would be a quite big project, and i haven't find a project in the wild doing this. I would be glad to hear about if there is.

Also, I know I could create multiple discovery checks in the discovery rule but I would end up with 40+ checks in the discovery, and should add them manually every time we have a new template... I would like to have a solution where there is as little manipulation as possible to add a new template.

Does someone have bump into this problem, and got a scalable solution?

I'm using zabbix 3.0.3


The most flexible and powerful approach will be to use the Zabbix API to create hosts and link them to appropriate templates from Puppet.

One project that handles that is https://github.com/voxpupuli/puppet-zabbix#module-description , and it seems to be tested with Zabbix 3.0 already. There are others like https://github.com/purplehazech/puppet-zabbix and probably more.

You should try them out yourself to see which one fits your need the best.

You already are aware of the Zabbix network discovery, but the 255 char limit makes it not that useful for you. You could use shorter codes instead of full names like "apache::default_confd_files", but that might be harder to maintain and there's probably still some chance to hit the limit.

The active agent auto-registration has the same length limit, so not that much different.

As a hackish workaround, you could have the network discovery or auto-registration only create hosts and kick off a script, that uses zabbix_get to query an item key with all the roles the host has, then use the API to link the host to templates.

  • Well, voxpupuli use puppetdb and in our environment, we have multiple puppetdb servers, so the zabbix-server does not know about others puppetmasters... That's why I asked something else than puppetdb. About purplehazech, I guess it is possible to configure every hosts to connect via the API to the zabbix server... It would require a lot of changes in our puppet manifests, but yes, it could be done. – pbrideau May 25 '16 at 14:55
  • But really, I would like to use Zabbix specific solution (like network discovery or auto-registration) instead of puppet, and query the file /var/lib/puppet/state/classes.txt – pbrideau May 25 '16 at 15:00
  • Both network discovery & agent auto-registration have the limit - I expanded the answer to suggest a couple potential workarounds. – Richlv May 25 '16 at 16:00
  • Yeah, I gess i'll have to write my own discoverer that call the API, what I wanted to avoid in the first place... thanks @Richlv – pbrideau May 25 '16 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.