Page 1 of 1

eventhandler | start a VM

Posted: Mon Jan 07, 2019 3:37 am
by matanr
hi all,

I want to start a VM on ESXI with powercli script.

My nagios is installed on CestOs.
Also, i installed powershell and powercli on the CentOs.
my script to power on a vm from the centos is working good.
however, i seems that when i want to call it from nagios it doesnt work.
what do i do wrong?

the scrips:

Code: Select all

#!/usr/bin/pwsh -Command

connect-VIServer -Server *SOME IP* -User *SOME USER* -Password *SOME PASSWORD* 
Start-VM -VM "SOME SERVER"
the command:

Code: Select all

define command {

    command_name   restart-server
    command_line   /usr/local/nagios/libexec/eventhandlers/test1.ps1
}
the host:

Code: Select all

define host {

    contact_groups          Regular
    use                     windows-server          ; Inherit default values from a template
    host_name               test              ; The name we're giving to this host
    alias                   test       ; A longer name associated with the host
    address                 *SOME IP*             ; IP address of the host
    event_handler           restart-server
}
thank you.

Re: eventhandler | start a VM

Posted: Mon Jan 07, 2019 9:28 am
by scottwilkerson
When you test it from the command line are you running it as the nagios user?

Also, you may need to add the full path to connect-VIServer to make sure nagios knows where to find the file