Is connection monitoring possible from Nagios Core

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
gouravin
Posts: 8
Joined: Thu Feb 14, 2019 1:03 am

Is connection monitoring possible from Nagios Core

Post by gouravin »

Hi Community,

This question is very interesting for me and it looks we have to use some scripting to achieve this. Since I am new on Nagios so don't know how it treats script and what kind of scripting (Like PowerShell) it supports.

Now coming back to business and question is: -

I am monitoring one windows server using Naios and this windows machine is connected to a DB but this DB is not at all monitored by Nagios.
And now requirement is to monitor the connect between windows server and DB. If this connection goes down then should trigger and alert.

Could anyone suggest their views on it either we can do it or this is not possible with monitoring DB.

Thanks in advance :)
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Is connection monitoring possible from Nagios Core

Post by scottwilkerson »

Nagios can monitor almost anything if the data is available, but for one-offs like this you will need to write a custom plugin in the language of your choice to grab the data and determine what the dtate is, this is what is called a custom plugin.

Here are the plugin development guidelines
https://nagios-plugins.org/doc/guidelines.html
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Is connection monitoring possible from Nagios Core

Post by mcapra »

This can be done.

An agent like NCPA or NSClient++ could handle the "hop" you're describing. Essentially you'd have Nagios Core communicate with that agent (via one of the agent's associated plugins like check_ncpa or check_nrpe) to handle the PowerShell execution. Rather than having Nagios Core execute the PowerShell directly, it asks the agent running on the Windows machine to execute the PowerShell. I would recommend NCPA because it receives official support from the maintainers of Nagios Core/XI. Here's documentation for installing NCPA on Windows and getting your Nagios Core installation communicating with the NCPA agent:
https://www.nagios.org/ncpa/getting-started.php#windows

And here's how you can configure some basic "active checks" with NCPA for things like memory, cpu, and disk usage:
https://www.nagios.org/ncpa/getting-sta ... ive-checks

Once you've got the basics of NCPA figured out, and custom PowerShell that's giving you the information you want, you can dive into executing custom plugins (like your PowerShell) via NCPA:
https://www.nagios.org/ncpa/help/2.1/ap ... ng-plugins

Assuming you have PowerShell that can determine whether or not the connection is valid, all you'd really need to do as far as the PowerShell is concerned is make sure it conforms to the Nagios Plugin Development guidelines.
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: Is connection monitoring possible from Nagios Core

Post by scottwilkerson »

Thanks for the additional details @mcapra
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
gouravin
Posts: 8
Joined: Thu Feb 14, 2019 1:03 am

Re: Is connection monitoring possible from Nagios Core

Post by gouravin »

Hi Both,

I am really thankful for both you the way you have illustrated. But excuse for this silly question again.

I have script ready with me (could see below) and i am taking reference of this https://exchange.nagios.org/directory/P ... ll/details link to setup my requirement. But quite confuse how to run my script using nagios as in this blog he is using "check_updates=cmd /c echo scriptscheck_windows_updates.ps1; exit $LastExitCode | powershell.exe -command -" to run this. So how he is getting $LastExitCode (is it run time, and if i will run my script using ngaios what i will have) and what should i need to modify in my script and how i need to writie this given line in my NSC.ini file.

#Test-NetConnection "google.com" -Port 8080
$returnStateOK = 0
$returnStateCritical = 1
$Ipaddress= '172.217.166.110'
$Port= '8080'

$t = New-Object Net.Sockets.TcpClient
$t.Connect($Ipaddress,$Port)
if($t.Connected)
{
"Port $Port is operational"
$returnStateOK
}else
{
"Port $Port is down "
$returnStateCritical
}
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Is connection monitoring possible from Nagios Core

Post by scottwilkerson »

$LastExitCode is builtin to windows cmd and is the exit code of the last script to run.

In the plugin you linked to it exits depending on various values this can then be picked up from cmd as $LastExitCode
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
gouravin
Posts: 8
Joined: Thu Feb 14, 2019 1:03 am

Re: Is connection monitoring possible from Nagios Core

Post by gouravin »

Hi Experts,

I am using below PS script to check connection. This is checking connection on given IP from Nagios Monitor client on defined port.

$returnStateOK = 1
$returnStateCritical = 0
$Ipaddress= '10.130.259.601'
$Port= '8080'

$t = New-Object Net.Sockets.TcpClient
$t.Connect($Ipaddress,$Port)
if($t.Connected)
{
"Port $Port is operational"
$returnStateOK
}else
{
"Port $Port is closed "
$returnStateCritical
}


This script is generally working fine however when i am trying to use this through Nagios. I have below errors: -\
Error
Error
Nagios Error
Nagios Error
Please help me what i missed here, Thanks in advance :)
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: Is connection monitoring possible from Nagios Core

Post by dwhitfield »

What version of NSClient are you using? If memory serves, NSC.ini is the 3.x-type ini file, and NSClient 3.x is probably not what you want.

That said, the error looks like you have a networking issue. Firewall, perhaps?
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Is connection monitoring possible from Nagios Core

Post by scottwilkerson »

dwhitfield wrote:What version of NSClient are you using? If memory serves, NSC.ini is the 3.x-type ini file, and NSClient 3.x is probably not what you want.

That said, the error looks like you have a networking issue. Firewall, perhaps?
I agree there could be a firewall issue, also your script doesn't seem to be using the exit keyword as it should, may I suggest the following edits

Code: Select all

$returnStateOK = 1
$returnStateCritical = 0
$Ipaddress= '10.130.259.601'
$Port= '8080'

$t = New-Object Net.Sockets.TcpClient
$t.Connect($Ipaddress,$Port)
if($t.Connected)
{
Write-Host "Port $Port is operational"
exit $returnStateOK
}else
{
Write-Host "Port $Port is closed "
exit $returnStateCritical
}
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
gouravin
Posts: 8
Joined: Thu Feb 14, 2019 1:03 am

Re: Is connection monitoring possible from Nagios Core

Post by gouravin »

Hi All,

Thanks a lot for the help, I have managed this to be monitor.

Learning: - I got to know do not forget to add $exit in powershell script.

We could close this thread.
Locked