I've created a script the triggers when a host goes into a DOWN state. When it triggers it'll grab the private IP address of the AWS Instance(host), and use that IP to run the command "ipconfig /registerdns" on the instance using winexe. The script is successfully executing and grabbing the arguments from the command line. This issue is described in the second scenario below:
Nagios XI version: 5.6.7
PowerShell Core version = 6.2.3 (installed through yum)
Linux = Linux 3.10.0-862.14.4.el7.x86_64
Scenario 1: When the script is ran through SSH on the nagios server, logged in as root, it executes successfully.
Here's an example of the command that i run through SSH with the arguments manually inputted:
Code: Select all
pwsh /usr/local/nagios/libexec/powershell/RegisterDNS.ps1 "SWSIM-9E20A0" "check_icmp: Failed to resolve SWSIM-9E20A0.prod02.aws.local" "DOWN"
Scenario 2: When the script is executed by the Event Handler, it fails due to the powershell module it needs to import
AWS.Tools.EC2 is not able to get imported (It says an associated cmdlet can't be found)
Here's the error message that gets captured from line 18
Code: Select all
The error message was The term 'Get-EC2Tag' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again. for SWSIM-9E20A0
In Nagios, i have the command for the script to run as follows:
Code: Select all
pwsh /usr/local/nagios/libexec/powershell/RegisterDNS.ps1 "$HOSTNAME$" "$HOSTOUTPUT$" "$HOSTSTATE$"
The only difference between these two processes is that the 2nd scenario is the script getting executed by Nagios. I can't figure out why this is not working, please help!
i have the script with redacted personal info attached. RegisteredDNSShared.zip
What user does nagios execute event handler commands as?
I have the permissions set up as such for the script itself,
Code: Select all
-rwxrwxrwx 1 root root 2688 Oct 31 10:47 RegisterDNS.ps1
i have the module getting automatically imported whenever a pwsh session starts, so really the importing of the module within the script shouldn't be necessary but i have it configured as such given the issue i'm having.
/root/.config/powershell/Microsoft.PowerShell_profile.ps1
Code: Select all
$PSModuleAutoloadingPreference = 'All'
Import-Module AWS.Tools.Common,AWS.Tools.EC2
For folks who don't know, AWS released a version of their AWSPowerShell.NetCore that has each service separated into their own modules, hence why you see those specific modules. I first started out using their original module, AWSPowerShell.NetCore, but moved over to this other version due to thinking it it may help but there is
no difference of the results.
You do not have the required permissions to view the files attached to this post.