Page 1 of 1

Checks if a specific user is logged on to a Windows system.

Posted: Wed Oct 20, 2021 7:56 am
by Aldo Lanfranconi
Hello, I would like to chek if a specific user is logged on to a windows server.

I have Nagios 5.8.6
I use NCPA client

I have found this topic on Nagios Exchange:
https://exchange.nagios.org/directory/P ... er/details
but this plugin seems to be developed to work with NSCLIENT++

How can I make it work with NCPA? or are there any other similar plugin or builtin check on NCPA?

Thanks in advance.

Re: Checks if a specific user is logged on to a Windows syst

Posted: Thu Oct 21, 2021 9:32 am
by gsmith
hi

What version of Windows server are you running?

Thanks

Re: Checks if a specific user is logged on to a Windows syst

Posted: Thu Oct 21, 2021 10:58 am
by gsmith
Hi

Here is what I came up with, it's rough but works.

Create a file called check_user.ps1 and put it in C:\Program Files (x86)\Nagios\NCPA\plugins on the remote Windows machine.

check_user.ps1:

Code: Select all

$exitcode=2
if (((quser) | Out-String).contains($Args[0])) {
  $exitcode=0
}
 
Write-Host("User checked was: " + $Args[0])
#Write-Host($exitcode)
exit $exitcode
In Nagios set it up as shown, with the $ARG1$ shown:
-t 'gjstoken' -P 5693 -M 'plugins/check_user.ps1' -a 'administrator'
check_user.jpg
Thanks

Re: Checks if a specific user is logged on to a Windows syst

Posted: Thu Oct 21, 2021 11:34 am
by Aldo Lanfranconi
Awsome!!, It works like a charm!, Thanks a lot!

Re: Checks if a specific user is logged on to a Windows syst

Posted: Thu Oct 21, 2021 12:22 pm
by gsmith
Hi

Glad it's working for you.

Have a good day!