PowerShell Scripts with Administrative Privileges

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
ganesh.batwal
Posts: 16
Joined: Thu May 04, 2017 7:48 am

PowerShell Scripts with Administrative Privileges

Post by ganesh.batwal »

Dear Support,
Pl help us in how to execute the windows PowerShell script with Administrative Privileges via NCPA/NRPE agent in Nagios.
As we are not able to configure the windows IIS pool monitoring by using the PowerShell script.
Here we are referring the attached link for reference.
https://exchange.nagios.org/directory/P ... ol/details

Error message while executing the script via NRPE Agent:-


[nagios@jet-nagios-prod ~]$ /usr/local/nagios/libexec/check_nrpe -H 172.28.52.78 -p 5666 -t 60 -c check_ms_iis_application_pool -a '-A JetMBE'
scripts/powershell/check_ms_iis_application_pool.ps1 : The term
'scripts/powershell/check_ms_iis_application_pool.ps1' 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.
At line:1 char:1
+ scripts/powershell/check_ms_iis_application_pool.ps1 -A JetMBE; exit
$LastExitCo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (scripts/powersh...cation_pool.p
s1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException


/usr/local/nagios/libexec/check_ncpa.py -H 172.28.52.78 -t 'XXXXXX' -P 5693 -M 'plugins/check_ms_iis_application_pool.ps1' -a '-A JetMBE'
CRITICAL: Cannot retrieve the dynamic parameters for the cmdlet. Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).





Where as the same script is working fine on windows server.

PS C:\Users\GANESH.BATWAL\Downloads> .\check_ms_iis_application_pool.ps1 -A JetOBE
OK: Application Pool "JetOBE" with 1 Applications. {CPU: 100 %}{Memory: 643.84 MB} | 'pool_cpu'=100%;;;0;100 'pool_memory'=643.84MB;;;0; 'app_count'=1
PS C:\Users\GANESH.BATWAL\Downloads>
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: PowerShell Scripts with Administrative Privileges

Post by mcapra »

Can you share your NSClient++ configuration? Which version of NSClient++ are you using?

Which version of Windows and IIS are being used?

Did you follow the NSClient++ configuration item mentioned in the documentation?

Code: Select all

check_ms_iis_application_pool=cmd /c echo scripts/powershell/check_ms_iis_application_pool.ps1 $ARG1$; exit $LastExitCode | powershell.exe /noprofile -command -
My immediate assumption is that your NSClient++ command configuration isn't correctly resolving the PowerShell runtime, which the above example should handle more gracefully than simply providing a script with an extension and hoping the shell correctly resolves it.
Former Nagios employee
https://www.mcapra.com/
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: PowerShell Scripts with Administrative Privileges

Post by scottwilkerson »

The only way I know to do this is to setup the nsclient or NCPA service to start with an administrative user
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
ganesh.batwal
Posts: 16
Joined: Thu May 04, 2017 7:48 am

Re: PowerShell Scripts with Administrative Privileges

Post by ganesh.batwal »

Dear Support,
Thanks for the support, We have corrected the nsclient.ini configuration, Now we are able to run the powershell script via NRPE successfully.

/usr/local/nagios/libexec/check_nrpe -H 172.28.52.78 -p 5666 -t 60 -c check_ms_iis_application_pool -a '-A JetOBE'
OK: Application Pool "JetOBE" with 1 Applications. {CPU: 100 %}{Memory: 697.37 MB} |'pool_cpu'=100%;;;0;100 'pool_memory'=697.37MB;;;0 'app_count'=1


But the same script is not working via NCPA, Could you pl help us on the below mention error message via ncpa.

/usr/local/nagios/libexec/check_ncpa.py -H 172.28.52.78 -t 'XXXXXXXXX' -P 5693 -M 'plugins/check_ms_iis_application_pool.ps1' -a '-A JetMBE'
CRITICAL: Cannot retrieve the dynamic parameters for the cmdlet. Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).


Here we are using NCPA2.1.5 client, ncpa.ini configuration is attached for reference.
You do not have the required permissions to view the files attached to this post.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: PowerShell Scripts with Administrative Privileges

Post by lmiltchev »

It seems like this is a problem with using the 32-bit powershell. Have you seen the following piece of code in the ncpa.cfg file?

Code: Select all

# Since windows NCPA is 32-bit, if you need to use 64-bit powershell, try the following for
# the powershell plugin definition:
#.ps1 = c:\windows\sysnative\windowspowershell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File $plugin_name $plugin_args
Try commenting out this line:

Code: Select all

.ps1 = powershell -ExecutionPolicy Bypass -File $plugin_name $plugin_args
un-commenting this one:

Code: Select all

#.ps1 = c:\windows\sysnative\windowspowershell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File $plugin_name $plugin_args
so that it is going to look like this:

Code: Select all

.ps1 = c:\windows\sysnative\windowspowershell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File $plugin_name $plugin_args
and restarting the ncpa service.

If you are still experiencing this problem after making these mods, we will have to escalate the issue to our developers. Let us know if this helped.
Be sure to check out our Knowledgebase for helpful articles and solutions!
ganesh.batwal
Posts: 16
Joined: Thu May 04, 2017 7:48 am

Re: PowerShell Scripts with Administrative Privileges

Post by ganesh.batwal »

Thanks for the Support.
After un-commenting the below mention line in ncpa.cfg we are able to executing the powershell script successfully.

#.ps1 = c:\windows\sysnative\windowspowershell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File $plugin_name $plugin_args

/usr/local/nagios/libexec/check_ncpa.py -H 172.28.52.78 -t 'XXXXXXX' -P 5693 -M 'plugins/check_ms_iis_application_pool.ps1' -a '-A JetOBE'
OK: Application Pool "JetOBE" with 1 Applications. {CPU: 100 %}{Memory: 496 MB} | 'pool_cpu'=100%;;;0;100 'pool_memory'=496MB;;;0; 'app_count'=1
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: PowerShell Scripts with Administrative Privileges

Post by lmiltchev »

I am glad I could help! :)

I will be closing this topic now. If you have any more questions/issues, please start a new thread.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked