Check NCPA , PSSnappin error for Exchange 2013

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
Keystone
Posts: 28
Joined: Wed Jan 17, 2018 12:09 pm

Check NCPA , PSSnappin error for Exchange 2013

Post by Keystone »

System : Windows 2012ServerR2 6.3.9600
where the servers are located [In DMZ or not] : Servers are in the DMZ and not domain members.
ncpac version : 2.1.1
Version of Exchange : Exchange 2013

one of my team is attempting to load a Powershell PSSnapin for exchange on these systems so I can interrogate the message queue for monitoring. When using ncpa to load the service monitor Exchange Queue Length, the script fails.

The error is related to loading the Exchange powershell snapin loaded to execute the powershell script that returns queue length. The script get-QueueLength.ps1 runs on the server however fails to load when executed from Nagios


[nagios@monrck-vccn003 ~]$ /usr/local/nagios/libexec/check_ncpa.py -H server -t 'token' -P 5693 -M 'plugins/Nagios_Get-QueueLength.ps1'
Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version
4.
At C:\Program Files (x86)\Nagios\NCPA\plugins\Nagios_Get-QueueLength.ps1:8
char:1
+ Add-PSSnapin "Microsoft.Exchange.Management.PowerShell.SnapIn"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Microsoft.Excha...werShell.Sna
pIn:String) [Add-PSSnapin], PSArgumentException
+ FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.Ad
dPSSnapinCommand

We Also Tried the some troubleshooting steps by following a post #53056 and we still face with the below errors


.ps1 = C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "C:\Program Files\Microsoft\Exchange Server\V15\bin\Microsoft.Exchange.PowerShell.Configuration.dll"

Still getting this:

$ /usr/local/nagios/libexec/check_ncpa.py -H server -t 'token' -P 5693 -M 'plugins/Nagios_Get-QueueLength.ps1'
Processing -File '"Microsoft.Exchange.Management.PowerShell.SnapIn"' failed: Illegal characters in path. Specify a valid path for the -File parameter.


Or when I use single quotes around the full snappin name like this 'Microsoft.Exchange.Management.PowerShell.SnapIn':
$ /usr/local/nagios/libexec/check_ncpa.py -H server -t 'token' -P 5693 -M 'plugins/Nagios_Get-QueueLength.ps1'
Processing -File ''Microsoft.Exchange.Management.PowerShell.SnapIn'' failed because the file does not have a '.ps1' extension. Specify a valid Windows PowerShell script file name, and then try again.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Check NCPA , PSSnappin error for Exchange 2013

Post by lmiltchev »

It is possible that you need to modify the ncpa.cfg by using the 64-bit powershell. Comment out the "default .ps1" line (or whatever you currently have), e.g.:

Code: Select all

# .ps1 = powershell -ExecutionPolicy Bypass -File $plugin_name $plugin_args
and uncomment the following line:

Code: Select all

.ps1 = c:\windows\sysnative\windowspowershell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File $plugin_name $plugin_args
Save, exit, and restart NCPA services on the Windows machine. Try your check again. Did this help?
Be sure to check out our Knowledgebase for helpful articles and solutions!
Keystone
Posts: 28
Joined: Wed Jan 17, 2018 12:09 pm

Re: Check NCPA , PSSnappin error for Exchange 2013

Post by Keystone »

we tried that and we still get issue. Added our ncpa Config screenshot.

We do have this work on other exchange servers, only thing that seems different to this server is that its not a domain members.

we tried bunch of combination

.ps1 = %SystemRoot%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File $plugin_name $plugin_args
.ps1 = %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File $plugin_name $plugin_args

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

The script works fine only when executed locally from powershell in the machine,
The same script when ran form powershell(x86) it fails with the same error

We did restart NCPA listener service every time we tested
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: Check NCPA , PSSnappin error for Exchange 2013

Post by lmiltchev »

The same script when ran form powershell(x86) it fails with the same error
Previously, you showed us a few different errors. Which of these are you seeing now? Can you show us the ncpa_listener.log?
Be sure to check out our Knowledgebase for helpful articles and solutions!
Keystone
Posts: 28
Joined: Wed Jan 17, 2018 12:09 pm

Re: Check NCPA , PSSnappin error for Exchange 2013

Post by Keystone »

Attached is the ncpa_listener log file
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: Check NCPA , PSSnappin error for Exchange 2013

Post by lmiltchev »

I spoke to our developers, and they believe it is possible that you are not using the proper powershell version. You can try using:

Code: Select all

.ps1 = C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File $plugin_name $plugin_args
to see if this is going to fix the issue.

We don't have access to your system, and cannot test this in-house, so it is hard to troubleshoot the issue. According to Microsoft, Add-PSSnapin adds the snap-in only to the current session. Have you tried adding the snap-in to your Windows PowerShell profile?

https://docs.microsoft.com/en-us/powers ... rshell-5.1
Be sure to check out our Knowledgebase for helpful articles and solutions!
Keystone
Posts: 28
Joined: Wed Jan 17, 2018 12:09 pm

Re: Check NCPA , PSSnappin error for Exchange 2013

Post by Keystone »

Thank you, Adding the PSSnappin to $profile.AllUsersAllHosts fixed the issue.
User avatar
mbellerue
Posts: 1403
Joined: Fri Jul 12, 2019 11:10 am

Re: Check NCPA , PSSnappin error for Exchange 2013

Post by mbellerue »

Glad to hear this worked!
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked