How to debug a configuration issue?

Try log(Json.encode(m)).

Json.encode(m) leads to “null” in the log file.

I think… nothing w/o knowing the complete host, service and command definitions this comes from.

Fair objection. :slight_smile:

Many details are above already. What else do you want to see?
Maybe better via private msg/email?

Thanks,
Andy

Maybe the config even looks good, but an API query changes our minds.

Please log also macro("$host.name$") and macro("$service.name$") and share an API query result for that checkable.

[2020-07-15 13:27:54 +0200] information/config: Andy-DEBUG Start
[2020-07-15 13:27:54 +0200] information/config: null
[2020-07-15 13:27:54 +0200] information/config: cocodrilo.XXXX.de
[2020-07-15 13:27:54 +0200] information/config: Andy-Test
[2020-07-15 13:27:54 +0200] information/config: Andy-DEBUG End

Code:

object CheckCommand "andytest" {
        command = [ PluginLocalDir + "/check_andytest" ]

        arguments = {
        "--warning" = {
            value = "$andytest_warning$"
        }
        "--critical" = {
            value = "$andytest_critical$"
        }
        "--perfparse" = {
 //          set_if = "$andytest_perfdata$"
            set_if = () => { var m = macro("$andytest_perfdata$"); log("Andy-DEBUG Start"); log(Json.encode(m)); log( macro("$host.name$") ); log( macro("$service.name$") ); log("Andy-DEBUG End"); return m }
            description = "Add performance data"
        }
    }

    vars.andytest_perfdata = true
    vars.andytest_warning = "15"
    vars.andytest_critical = "5"
}

Query:

  $ echo "get_service(\"cocodrilo.xxxx.de\", \"Andy-Test\").last_check_result.command" | ICINGA2_API_PASSWORD="xxxxx" /usr/sbin/icinga2 console --connect https://root@localhost:5665/ 
    Icinga 2 (version: r2.11.4-1)
    Type $help to view available commands.
    <1> => get_service("cocodrilo.xxxx.de", "Andy-Test").last_check_result.command
    [ "/usr/lib/nagios/plugins/check_by_ssh", "-C", "'/var/lib/nagios/plugins/check_andytest'", "-H", "127.0.0.1", "-p", "122", "-q", "-t", "90" ]

Result:

$ /usr/lib/nagios/plugins/check_by_ssh -C '/var/lib/nagios/plugins/check_andytest' -H 127.0.0.1 -p 122 -q -t 90
OK - Andy-Test passed.

@Al2Klimov
Isn’t that what you meant?
Andy

Please share this one:

… and the host.

object Host NodeName {
  import "generic-host"
  address = "127.0.0.1"
  address6 = "::1"
  vars.os = "Linux"
  
  vars.http_vhosts["http"] = {
    http_uri = "/"
  }
  vars.http_vhosts["Icinga Web 2"] = {
    http_uri = "/icingaweb2"
  }
  vars.http_vhosts["cocodrilo.xxxx.de"] = {
    http_vhost = "cocodrilo.xxxx.de"
  }
  
  vars.disks["disk"] = {
  }
  vars.disk_wfree = "5%"
  vars.disk_cfree = "3%"

  vars.procs.procs_warning = 200
  vars.procs.procs_critical = 250

  vars.users.users_wgreater = 5
  vars.users.users_cgreater = 10
}

object Service "Andy-Test" {
  check_command = "andytest"
  import "ssh-service"
  host_name = "cocodrilo.xxxx.de"
}

Defining service objects without Apply Rule does not allow access of (host) variables. Details can be found here.

This doesn’t apply during check execution.

Thanks, interesting (and pretty weird) but I do have an apply rule.

Is there anything else you need to analyze this?

Maybe you guys just are on vacation?
Just a ping to remind that there still is an open question/issue. :slight_smile:

No, waiting for you to provide the debug console outputs.

I thought I did 18d ago:

If that’s not what you need, please let me know what else you want to see.
Thanks,
Andy

Uhm wait. Maybe you meant this?

Icinga 2 (version: r2.11.4-1)
<1> => get_service("cocodrilo.xxxx.de Andy-Test")
{
    __name = "cocodrilo.xxxx.de!Andy-Test"
    acknowledgement = 0.000000
    acknowledgement_expiry = 0.000000
    action_url = ""
    active = true
    check_attempt = 1.000000
    check_command = "by_ssh"
    check_interval = 600.000000
    check_period = ""
    check_timeout = null
    command_endpoint = ""
    display_name = "Andy-Test"
    downtime_depth = 0.000000
    enable_active_checks = true
    enable_event_handler = true
    enable_flapping = false
    enable_notifications = true
    enable_passive_checks = true
    enable_perfdata = true
    event_command = ""
    extensions = {
        DbObject = {
            type = "Object"
        }
    }
    flapping = false
    flapping_buffer = 0.000000
    flapping_current = 0.000000
    flapping_index = 4.000000
    flapping_last_change = 0.000000
    flapping_threshold = 0.000000
    flapping_threshold_high = 30.000000
    flapping_threshold_low = 25.000000
    force_next_check = false
    force_next_notification = false
    groups = [ ]
    ha_mode = 0.000000
    handled = false
    host = {
        __name = "cocodrilo.xxxx.de"
        acknowledgement = 0.000000
        acknowledgement_expiry = 0.000000
        action_url = ""
        active = true
        address = "127.0.0.1"
        address6 = "::1"
        check_attempt = 1.000000
        check_command = "hostalive"
        check_interval = 60.000000
        check_period = ""
        check_timeout = null
        command_endpoint = ""
        display_name = "cocodrilo.xxxx.de"
        downtime_depth = 0.000000
        enable_active_checks = true
        enable_event_handler = true
        enable_flapping = false
        enable_notifications = true
        enable_passive_checks = true
        enable_perfdata = true
        event_command = ""
        extensions = {
            DbObject = {
                type = "Object"
            }
        }
        flapping = false
        flapping_buffer = 0.000000
        flapping_current = 0.000000
        flapping_index = 18.000000
        flapping_last_change = 0.000000
        flapping_threshold = 0.000000
        flapping_threshold_high = 30.000000
        flapping_threshold_low = 25.000000
        force_next_check = false
        force_next_notification = false
        groups = [ "linux-servers
        ha_mode = 0.000000
        handled = false
        icon_image = ""
        icon_image_alt = ""
        last_check = 1597097531.754861
        last_check_result = {
            active = true
            check_source = "cocodrilo.xxxx.de"
            command = [ "/usr/lib/nagios/plugins/check_ping -H 127.0.0.1 -c 5000,100% -w 3000,80%
            execution_end = 1597097531.754768
            execution_start = 1597097527.665351
            exit_status = 0.000000
            output = "PING OK - Packet loss = 0%, RTA = 0.06 ms"
            performance_data = [ "rta=0.059000ms;3000.000000;5000.000000;0.000000 pl=0%;80;100;0
            schedule_end = 1597097531.754861
            schedule_start = 1597097527.664909
            state = 0.000000
            ttl = 0.000000
            type = "CheckResult"
            vars_after = {
                attempt = 1.000000
                reachable = true
                state = 0.000000
                state_type = 1.000000
            }
            vars_before = {
                attempt = 1.000000
                reachable = true
                state = 0.000000
                state_type = 1.000000
            }
        }
        last_hard_state = 0.000000
        last_hard_state_change = 1584400993.462069
        last_hard_state_raw = 0.000000
        last_reachable = true
        last_state = 0.000000
        last_state_change = 1584400993.462069
        last_state_down = 0.000000
        last_state_raw = 0.000000
        last_state_type = 1.000000
        last_state_unreachable = 0.000000
        last_state_up = 1597097531.754885
        max_check_attempts = 3.000000
        name = "cocodrilo.xxxx.de"
        next_check = 1597097591.124902
        notes = ""
        notes_url = ""
        original_attributes = null
        package = "_etc"
        pause_called = false
        paused = false
        previous_state_change = 1584400993.462069
        problem = false
        resume_called = true
        retry_interval = 30.000000
        severity = 8.000000
        source_location = {
            first_column = 0.000000
            first_line = 1.000000
            last_column = 19.000000
            last_line = 1.000000
            path = "/etc/icinga2/conf.d/hosts/cocodrilo.xxxx.de.conf"
        }
        start_called = true
        state = 0.000000
        state_loaded = true
        state_raw = 0.000000
        state_type = 1.000000
        stop_called = false
        suppressed_notifications = 0.000000
        templates = [ "cocodrilo.xxxx.de generic-host
        type = "Host"
        vars = {
            disk_cfree = "3%"
            disk_wfree = "5%"
            disks = {
                disk = {
                }
            }
            http_vhosts = {
                "CERT xxxx.de" = {
                    http_certificate = "27,15"
                    http_ssl = true
                    http_vhost = "cocodrilo.xxxx.de"
                }
                "Icinga Web 2" = {
                    http_uri = "/icingaweb2"
                }
                "cocodrilo.xxxx.de" = {
                    http_vhost = "cocodrilo.xxxx.de"
                }
                http = {
                    http_uri = "/"
                }
            }
            lm_sensors_nodrives = true
            lm_sensors_sanitize = true
            lmsensors = {
                "Sensor Core0" = {
                    lm_sensors_high = "Core0=60,85"
                }
                "Sensor Core1" = {
                    lm_sensors_high = "Core1=60,85"
                }
                "Sensor Core2" = {
                    lm_sensors_high = "Core2=60,85"
                }
                "Sensor Core3" = {
                    lm_sensors_high = "Core3=60,85"
                }
                "Sensor temp1" = {
                    lm_sensors_high = "temp1=50,80"
                }
                "Sensor temp2" = {
                    lm_sensors_high = "temp2=50,80"
                }
            }
            mysql_health_password = "XXXXXXXXXXXXX"
            mysql_health_username = "nagios"
            mysqlserver = 1.000000
            netinterfaces = {
                "netusage br0" = {
                    netusage_bandwidth = "1G"
                    netusage_interface = "br0"
                }
                "netusage tun0" = {
                    netusage_bandwidth = "100M"
                    netusage_interface = "tun0"
                }
                "netusage wg0" = {
                    netusage_bandwidth = "100M"
                    netusage_interface = "wg0"
                }
            }
            notification = {
                mail = {
                    groups = [ "icingaadmins
                }
            }
            os = "Linux"
            procs = {
                procs_critical = 250.000000
                procs_warning = 200.000000
            }
            smartdiskchecks = {
                "SMART Status HGST HTE721010A9E630 #1" = {
                    smart_attributes_device = "/dev/disk/by-id/ata-HGST_HTE721010A9E630_JR10036P0E2LSK"
                }
                "SMART Status HGST HTE721010A9E630 #2" = {
                    smart_attributes_device = "/dev/disk/by-id/ata-HGST_HTE721010A9E630_JR10036P0E3LAK"
                }
            }
            swap = {
                swap_cfree = 60.000000
                swap_wfree = 65.000000
            }
            users = {
                users_cgreater = 10.000000
                users_wgreater = 5.000000
            }
        }
        version = 0.000000
        volatile = false
        zone = ""
    }
    host_name = "cocodrilo.xxxx.de"
    icon_image = ""
    icon_image_alt = ""
    last_check = 1597097016.168752
    last_check_result = {
        active = true
        check_source = "cocodrilo.xxxx.de"
        command = [ "/usr/lib/nagios/plugins/check_by_ssh -C '/var/lib/nagios/plugins/check_andytest' -H 127.0.0.1 -p 122 -q -t 90
        execution_end = 1597097016.168688
        execution_start = 1597097015.871149
        exit_status = 0.000000
        output = "OK - Andy-Test passed."
        performance_data = [ ]
        schedule_end = 1597097016.168752
        schedule_start = 1597097015.870000
        state = 0.000000
        ttl = 0.000000
        type = "CheckResult"
        vars_after = {
            attempt = 1.000000
            reachable = true
            state = 0.000000
            state_type = 1.000000
        }
        vars_before = {
            attempt = 1.000000
            reachable = true
            state = 0.000000
            state_type = 1.000000
        }
    }
    last_hard_state = 0.000000
    last_hard_state_change = 1595163697.165764
    last_hard_state_raw = 0.000000
    last_reachable = true
    last_state = 0.000000
    last_state_change = 1595163697.165764
    last_state_critical = 0.000000
    last_state_ok = 1597097016.168774
    last_state_raw = 0.000000
    last_state_type = 1.000000
    last_state_unknown = 1595163638.835292
    last_state_unreachable = 0.000000
    last_state_warning = 0.000000
    max_check_attempts = 5.000000
    name = "Andy-Test"
    next_check = 1597097615.870000
    notes = ""
    notes_url = ""
    original_attributes = null
    package = "_etc"
    pause_called = false
    paused = false
    previous_state_change = 1595163697.165764
    problem = false
    resume_called = true
    retry_interval = 60.000000
    severity = 8.000000
    source_location = {
        first_column = 1.000000
        first_line = 157.000000
        last_column = 26.000000
        last_line = 157.000000
        path = "/etc/icinga2/conf.d/hosts/cocodrilo.xxxx.de.conf"
    }
    start_called = true
    state = 0.000000
    state_loaded = true
    state_raw = 0.000000
    state_type = 1.000000
    stop_called = false
    suppressed_notifications = 0.000000
    templates = [ "Andy-Test ssh-service generic-service
    type = "Service"
    vars = {
        by_ssh_arguments = {
            arguments = [ ]
            deprecated = false
            name = "<anonymous>"
            side_effect_free = false
            type = "Function"
        }
        by_ssh_command = {
            arguments = [ ]
            deprecated = false
            name = "<anonymous>"
            side_effect_free = false
            type = "Function"
        }
        by_ssh_port = "122"
        by_ssh_quiet = 1.000000
        by_ssh_timeout = 90.000000
        check_command = "andytest"
        original_check_command = "andytest"
    }
    version = 0.000000
    volatile = false
    zone = ""
}

I see in neither the host nor the service the custom var you’re missing – i.e. you actually didn’t set it.

That’s exactly the problem (the bug?)
I did set them as you can see in my posts before.
But icinga seems to ignore these lines. Why?

No clue either?
Does it help to open an official bug report?