0

I am trying to create Zabbix items using Ansible and Zabbix API. The problem is that preprocessing params must have a newline between them, that cannot be in a valid JSON value.

The JSON I tried first is as follows:

{                                                                                                                                                                                                                                                                
"jsonrpc": "2.0",                                                                                                                                                                                                                                            
"method": "item.create",                                                                                                                                                                                                                                     
"params": {                                                                                                                                                                                                                                                  
    "name": "{{ item.fqdn }} certificate status",                                                                                                                                                                                                            
    "key": "ssl-cert-check[-s,{{ item.fqdn }},-p,443,-n]",                                                                                                                                                                                                   
    "hostid": "{{ hostid }}",                                                                                                                                                                                                                                
    "type": 10,                                                                                                                                                                                                                                              
    "value_type": 0,                                                                                                                                                                                                                                         
    "delay": "1d",                                                                                                                                                                                                                                           
    "history": "9125d",                                                                                                                                                                                                                                      
    "trends": "9125d",                                                                                                                                                                                                                                       
    "units": "days to expiration",                                                                                                                                                                                                                           
    "preprocessing": [                                                                                                                                                                                                                                       
         {                                                                                                                                                                                                                                                   
             "type": 5,                                                                                                                                                                                                                                      
             "params": "days=([0-9-]*)$
\1",                                                                                                                                                                                                            
             "error_handler": 1,                                                                                                                                                                                                                             
             "error_handler_params": ""                                                                                                                                                                                                                      
         }                                                                                                                                                                                                                                                   
     ]                                                                                                                                                                                                                                                       
},                                                                                                                                                                                                                                                           
"auth": "{{ zabbix_auth }}",                                                                                                                                                                                                                                 
"id": 1                                                                                                                                                                                                                                                      
}                                                                                                                                                                                                                 

This failed with Invalid JSON error.

I also tried \n \\n and \u000A instead of the newline, those produced an Invalid params. error.

My question is: Is there a way to create a Zabbix item with regexp preprocessing through the Zabbix API, and how?

P.s.: I am aware that a valid workaround is to create a wrapper script for my external script, which will do the preprocessing. I will do just that after sending this question. However, the question is still valid, as it is not always a feasible solution.

P.Péter
  • 569
  • 2
  • 6
  • 24

0 Answers0