Score:0

create item with regex preprocessing using the zabbix API

in flag

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.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.