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>
PowerShell Scripts with Administrative Privileges
-
ganesh.batwal
- Posts: 16
- Joined: Thu May 04, 2017 7:48 am
Re: PowerShell Scripts with Administrative Privileges
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?
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.
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 -Former Nagios employee
https://www.mcapra.com/
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
The only way I know to do this is to setup the nsclient or NCPA service to start with an administrative user
-
ganesh.batwal
- Posts: 16
- Joined: Thu May 04, 2017 7:48 am
Re: PowerShell Scripts with Administrative Privileges
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.
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.
Re: PowerShell Scripts with Administrative Privileges
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?
Try commenting out this line:
un-commenting this one:
so that it is going to look like this:
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.
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_argsCode: Select all
.ps1 = powershell -ExecutionPolicy Bypass -File $plugin_name $plugin_argsCode: Select all
#.ps1 = c:\windows\sysnative\windowspowershell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File $plugin_name $plugin_argsCode: Select all
.ps1 = c:\windows\sysnative\windowspowershell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File $plugin_name $plugin_argsIf 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
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
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
Re: PowerShell Scripts with Administrative Privileges
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.
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!