Ad Widget

Collapse

List the value of a macro from all hosts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sambhu.prakash
    Junior Member
    • Apr 2021
    • 20

    #1

    List the value of a macro from all hosts

    Hi All,

    Is there a way to list the value of a given macro from all hosts regardless its a host level, template level or a global macro using a SQL query or API request?
    For some reason, I cannot get it right in one go using usermacro.get API method.

    I also tried using host.get >> selectMacros and template.get >> selectMacros and selectHosts.

    host.get

    PHP Code:
    {
        
    "jsonrpc" "2.0",
        
    "method" "host.get",
        
    "params" : {
            
    "output" : [ "name" ],
            
    "selectMacros" : [ "macro","value" ],
            
    "groupids" "XX",
            
    "filter" : {
                
    "macro" : [ "{$MEMORY.UTIL.CRIT}""{$MEMORY.UTIL.MAX}]
            }
        },
        
    "id" 1

    This only gives me hostmacro, don't go a level down to find the corresponding inherited macro.

    template.get
    PHP Code:
    {
            
    "jsonrpc" "2.0",
            
    "method" "template.get",
            
    "params" : {
                    
    "output" : [ "host" ],
                    
    "templateids" : [ "XXXX" ],
                    
    "selectMacros" : [ "macro""value" ],
                    
    "selectHosts" : ["name"]
            },
            
    "id" 1

    And this only gives me the template level macro, doesn't respect the hostlevel macro if set.

    Am I doing something wrong?
    FYI : I understand the fact that runtime macros can only get the value on the time of an event. I am only looking for the static ones here.
    Last edited by sambhu.prakash; 08-05-2025, 21:21.
Working...