Running commands on a different host

This forum was archived to /woltlab and is now in read-only mode.
  • I'm trying to use Director to create a powershell command that checks veeam backups. I've tried adding the powershell command, but haven't had much luck with it yet but I'm sure I'll work it out.


    Anyway, before I bang my head against a wall with the powershell command, I need to know how I would run a command to pull data for Host A from a service running on Host B.


    What I want to do, is show in the host view some stats about its last backup/replica (We use Veeam). So, for example, the host will show its CPU load averages, RAM usage, Disk space etc, and also the last backup date/time, how long it took and how many MB/GB was backed up.


    Is this possible?

  • It's like it's trying to execute locally on the icinga server instead of the host.

    I also guess it is. Could you please go to your Director dashboard, Endpoints, choose your deployment endpoint (green icon), Inspect, go to Services, choose the service you are interested in - and copy & paste the shown details (or at least the command_endpoint and templates properties)?


    Cheers,
    Thomas

  • Sure:


    {
    attrs: {
    __name: "MTAPP02.xxxxxxx.local!Check Windows Backup",
    acknowledgement: 0,
    acknowledgement_expiry: 0,
    action_url: "",
    active: true,
    check_attempt: 1,
    check_command: "PowerShell",
    check_interval: 64800,
    check_period: "",
    check_timeout: null,
    command_endpoint: "",
    display_name: "Check Windows Backup",
    enable_active_checks: true,
    enable_event_handler: true,
    enable_flapping: false,
    enable_notifications: true,
    enable_passive_checks: true,
    enable_perfdata: true,
    event_command: "",
    flapping: false,
    flapping_last_change: 1465936778.450407,
    flapping_negative: 9054,
    flapping_positive: 0,
    flapping_threshold: 30,
    force_next_check: false,
    force_next_notification: false,
    groups: [],
    ha_mode: 0,
    host_name: "MTAPP02.xxxxxxx.local",
    icon_image: "",
    icon_image_alt: "",
    last_check: 1465936778.450394,
    last_check_result: {
    active: true,
    check_source: "icinga2.xxxxxxx.local",
    command: [
    "C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe",
    "-command",
    "& \'C:\\scripts\\check_backup.ps1\'"
    ],
    execution_end: 1465936778.450354,
    execution_start: 1465936778.450198,
    exit_status: 128,
    output: "execvpe(C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe) failed: No such file or directory",
    performance_data: [],
    schedule_end: 1465936778.450394,
    schedule_start: 1466001578.450000,
    state: 3,
    type: "CheckResult",
    vars_after: {
    attempt: 1,
    reachable: true,
    state: 3,
    state_type: 1
    },
    vars_before: {
    attempt: 1,
    reachable: true,
    state: 3,
    state_type: 1
    }
    },
    last_hard_state: 3,
    last_hard_state_change: 1465923804.485645,
    last_in_downtime: false,
    last_reachable: true,
    last_state: 3,
    last_state_change: 1465923685.713711,
    last_state_critical: 0,
    last_state_ok: 0,
    last_state_type: 1,
    last_state_unknown: 1465936778.450400,
    last_state_unreachable: 0,
    last_state_warning: 0,
    max_check_attempts: 5,
    name: "Check Windows Backup",
    next_check: 1466001578.450000,
    notes: "",
    notes_url: "",
    original_attributes: null,
    package: "director",
    paused: false,
    retry_interval: 1800,
    state: 3,
    state_type: 1,
    templates: [
    "Check Windows Backup",
    "Check Windows Backup",
    "Agent Based Service"
    ],
    type: "Service",
    vars: { ps_command: "& \'C:\\scripts\\check_backup.ps1\'" },
    version: 0,
    volatile: false,
    zone: "icinga2.xxxxxxx.local"
    },
    joins: {
    check_command: {
    __name: "PowerShell",
    active: true,
    arguments: {
    -command: {
    order: -1,
    value: "$ps_command$"
    }
    },
    command: [
    "C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe"
    ],
    env: null,
    execute: { type: "Function" },
    ha_mode: 0,
    name: "PowerShell",
    original_attributes: null,
    package: "director",
    paused: false,
    templates: [
    "PowerShell"
    ],
    timeout: 60,
    type: "CheckCommand",
    vars: null,
    version: 0,
    zone: "director-global"
    },
    host: {
    __name: "MTAPP02.xxxxxxx.local",
    acknowledgement: 0,
    acknowledgement_expiry: 0,
    action_url: "",
    active: true,
    address: "MTAPP02.xxxxxxx.local",
    address6: "",
    check_attempt: 1,
    check_command: "hostalive4",
    check_interval: 300,
    check_period: "",
    check_timeout: null,
    command_endpoint: "",
    display_name: "MTAPP02",
    enable_active_checks: true,
    enable_event_handler: true,
    enable_flapping: false,
    enable_notifications: true,
    enable_passive_checks: true,
    enable_perfdata: true,
    event_command: "",
    flapping: false,
    flapping_last_change: 1465998047.731859,
    flapping_negative: 2995,
    flapping_positive: 0,
    flapping_threshold: 30,
    force_next_check: false,
    force_next_notification: true,
    groups: [
    "Windows Server 2012 R2 Standard"
    ],
    ha_mode: 0,
    icon_image: "",
    icon_image_alt: "",
    last_check: 1465998047.731837,
    last_check_result: {
    active: true,
    check_source: "icinga2.xxxxxxx.local",
    command: [
    "/usr/lib/nagios/plugins/check_ping",
    "-4",
    "-H",
    "MTAPP02.xxxxxxx.local",
    "-c",
    "5000,100%",
    "-w",
    "3000,80%"
    ],
    execution_end: 1465998047.731793,
    execution_start: 1465998043.730177,
    exit_status: 0,
    output: "PING OK - Packet loss = 0%, RTA = 0.24 ms",
    performance_data: [
    "rta=0.237000ms;3000.000000;5000.000000;0.000000",
    "pl=0%;80;100;0"
    ],
    schedule_end: 1465998047.731837,
    schedule_start: 1465998343.730000,
    state: 0,
    type: "CheckResult",
    vars_after: {
    attempt: 1,
    reachable: true,
    state: 0,
    state_type: 1
    },
    vars_before: {
    attempt: 1,
    reachable: true,
    state: 0,
    state_type: 1
    }
    },
    last_hard_state: 0,
    last_hard_state_change: 1463540765.893679,
    last_in_downtime: false,
    last_reachable: true,
    last_state: 0,
    last_state_change: 1463540765.893679,
    last_state_down: 0,
    last_state_type: 1,
    last_state_unreachable: 0,
    last_state_up: 1465998047.731851,
    max_check_attempts: 3,
    name: "MTAPP02.xxxxxxx.local",
    next_check: 1465998343.730000,
    notes: "",
    notes_url: "",
    original_attributes: null,
    package: "director",
    paused: false,
    retry_interval: 60,
    state: 0,
    state_type: 1,
    templates: [
    "MTAPP02.xxxxxxx.local",
    "Windows Servers",
    "Icinga Agent"
    ],
    type: "Host",
    vars: {
    object_sid: "S-1-5-21-2969318330-2621487994-1129126803-5694",
    operatingsystem: "Windows Server 2012 R2 Standard",
    operatingsystemversion: "6.3 (9600)"
    },
    version: 0,
    volatile: false,
    zone: "icinga2.xxxxxxx.local"
    }
    },
    meta: {},
    name: "MTAPP02.xxxxxxx.local!Check Windows Backup",
    type: "Service"
    }

  • command_endpoint: "",

    This is your problem, the endpoint is not set. Your generated config can be shown as follows:


    Now, this basically looks correct. But unfortunately, apply and object are two completely different beasts in Icinga 2. What one might not expect is that host_name is defined for "applied service" but not for "dedicated service" once the command_endpoint is going to be set.


    It's just a matter of ordering, Icinga 2 config is to be read like code, as it is a DSL and not a configuration format. Given this, 'command_endpoint = host_name' is reached before host_name is set in the object example. While executing an apply rule the host_name is always set as assign/ignore rules are executed, hosts are returned, and then a service is created for each matching host. host_name is always set when reaching the first statement inside an apply rule.


    Weird, I know - but that's how it works. I'll have to find another way to render them. Moving host_name before imports would probably be the easiest and quickest solution. Even if I do not like how that would look like:


    Code
    1. object Service "dedicated service" {
    2. host_name = "example.com"
    3. import "on agent"
    4. check_command = "dummy"
    5. vars.other = "property"
    6. }

    Cheers,
    Thomas

  • Got ya, so is this just a matter of how the config is being rendered in director and not something I'm doing wrong? I know director is a work in progress, hopefully I've been helping you find out some of the bugs! :)

  • Ahh I understand now, so for now it only works if you apply this to a template due to how the config for dedicated services is rendered. Thanks Thomas for all your hard work, I've enjoyed learning Icinga and Director!

  • I pushed two commits that should finally fix this for all variants. host_name is now rendered before imports for services (if given), so like with apply rules it is now available for use in an inherited command_endpoint property.


    Cheers,
    Thomas