Is connection monitoring possible from Nagios Core

An open discussion forum for obtaining help with Nagios Core. Nagios Core users of all experience levels are welcome here. Subforum have been created for the discussion of Nagios Core and Nagios Plugin development.

NOTE: The SourceForge.net mailing lists have been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

Is connection monitoring possible from Nagios Core

Postby gouravin » Tue Apr 30, 2019 3:18 am

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 :)
gouravin
 
Posts: 8
Joined: Thu Feb 14, 2019 1:03 am

Re: Is connection monitoring possible from Nagios Core

Postby scottwilkerson » Tue Apr 30, 2019 11:53 am

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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
scottwilkerson
DevOps Engineer
 
Posts: 16271
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises

Re: Is connection monitoring possible from Nagios Core

Postby mcapra » Tue Apr 30, 2019 12:02 pm

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
http://www.mcapra.com/
User avatar
mcapra
 
Posts: 3578
Joined: Thu May 05, 2016 3:54 pm

Re: Is connection monitoring possible from Nagios Core

Postby scottwilkerson » Tue Apr 30, 2019 1:00 pm

Thanks for the additional details @mcapra
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
scottwilkerson
DevOps Engineer
 
Posts: 16271
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises

Re: Is connection monitoring possible from Nagios Core

Postby gouravin » Fri May 03, 2019 2:56 am

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/Plugins/Operating-Systems/Windows-NRPE/Check-Windows-Updates-using-Powershell/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
}
gouravin
 
Posts: 8
Joined: Thu Feb 14, 2019 1:03 am

Re: Is connection monitoring possible from Nagios Core

Postby scottwilkerson » Fri May 03, 2019 7:43 am

$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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
scottwilkerson
DevOps Engineer
 
Posts: 16271
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises

Re: Is connection monitoring possible from Nagios Core

Postby gouravin » Mon May 27, 2019 5:46 am

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_Notepad.JPG
Error

Error_NagiosScreen_Forums.jpg
Nagios Error


Please help me what i missed here, Thanks in advance :)
gouravin
 
Posts: 8
Joined: Thu Feb 14, 2019 1:03 am

Re: Is connection monitoring possible from Nagios Core

Postby dwhitfield » Mon May 27, 2019 1:23 pm

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?
dwhitfield
Former Nagios Staff
 
Posts: 4575
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN

Re: Is connection monitoring possible from Nagios Core

Postby scottwilkerson » Tue May 28, 2019 12:12 pm

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
}
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
scottwilkerson
DevOps Engineer
 
Posts: 16271
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises

Re: Is connection monitoring possible from Nagios Core

Postby gouravin » Mon Jun 03, 2019 9:19 am

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.
gouravin
 
Posts: 8
Joined: Thu Feb 14, 2019 1:03 am

Next

Return to Nagios Core

Who is online

Users browsing this forum: hpzaramk, MSN [Bot] and 34 guests

cron