Nagios Server Cluster report

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.
Post Reply
SalinaSJames
Posts: 13
Joined: Sat Feb 12, 2022 1:21 am

Nagios Server Cluster report

Post by SalinaSJames »

I am currently running Nagios Core 4.3.4 and looking for a way to run a reoccurring report to list per Pool the servers (IP address) within each pool. For instance..Default Pool 'PL_ASP_Citrix' (10.221.21.41, 10.221.21.56), Default Pool 'PL_AAS_TA' (172.17.21.174, 172.17.21.175). IF I can report on the State of each (Active, Draining, or disable) all the better. My aim is to generate either JSON, csv or xml page.
SantinoBoyer
Posts: 5
Joined: Thu Dec 29, 2022 3:21 am

Re: Nagios Server Cluster report

Post by SantinoBoyer »

Great post I would like to thank you for the efforts you have made in writing this interesting and knowledgeable article.
bobbrencher01
Posts: 1
Joined: Fri Apr 21, 2023 1:54 pm

Re: Nagios Server Cluster report

Post by bobbrencher01 »

The Nagios Server Cluster report provides comprehensive insights and analysis on the performance and health of the clustered Nagios servers, enabling efficient monitoring and management of network infrastructure for optimal reliability and uptime.
LauraH
Posts: 2
Joined: Mon May 08, 2023 4:01 pm
Contact:

Re: Nagios Server Cluster report

Post by LauraH »

To include the state of each server in the report (active, draining, or disabled), you can add the appropriate service checks to each server and include the service check results in the report. You can use the NagiosQL web interface to add service checks to each server and modify the report template to include the service check results.

Agile Onboarding[size]
BillieDuncan
Posts: 1
Joined: Tue May 09, 2023 10:56 pm
Contact:

Re: Nagios Server Cluster report

Post by BillieDuncan »

Thank you so much for the post
MercedesCole
Posts: 1
Joined: Mon May 22, 2023 12:35 pm

Re: Nagios Server Cluster report

Post by MercedesCole »

To generate a recurring report in Nagios Core 4.3.4 to list the servers within each pool, along with their IP addresses and state (Active, Draining, or Disabled), you can utilize Nagios Core's extensibility by writing a custom script or using an existing plugin. Here's an example approach using a custom script:

1. Create a script: Start by creating a script that retrieves the required information from Nagios Core and formats it into the desired output format (JSON, CSV, or XML). You can use your preferred scripting language (e.g., Bash, Python, Perl) to accomplish this. In this example, we'll use Python.

#!/usr/bin/env python3

import nagios
import json

# Nagios objects configuration file
nagios_cfg = '/path/to/nagios/etc/nagios.cfg'

# Parse Nagios configuration
cfg = nagios.cfg(nagios_cfg)

# List of pools
pools = []

# Loop through hosts
for host in cfg.hosts:
# Check if host belongs to a pool
if host.hostgroup_name.startswith('Default Pool'):
# Get pool name
pool_name = host.hostgroup_name.split(' ')[2]
# Get host IP address
ip_address = host.address
# Get host state
state = host.get_plugin_output().split('|')[0].strip()

# Append pool information
for pool in pools:
if pool['name'] == pool_name:
pool['servers'].append({'ip': ip_address, 'state': state})
break
else:
pools.append({'name': pool_name, 'servers': [{'ip': ip_address, 'state': state}]})

# Generate output
output = json.dumps(pools, indent=4)

# Print output
print(output)


Make sure to replace /path/to/nagios/etc/nagios.cfg with the actual path to your Nagios configuration file.

2.Save the script: Save the script on the Nagios Core server, for example, as pool_report.py, and make it executable (chmod +x pool_report.py).

3.Test the script: Run the script manually to ensure it generates the desired output.

4. Schedule recurring report: Use a cron job to schedule the script execution at regular intervals. For example, to run the script every day at 9 AM, open the crontab file with the command crontab -e and add the following line:

0 9 * * * /path/to/pool_report.py > /path/to/output.txt

Replace /path/to/pool_report.py with the actual path to the script, and /path/to/output.txt with the desired path to save the report output.

Output format: If you prefer a CSV or XML output, you can modify the script accordingly or use existing libraries/modules for generating those formats in your chosen programming language.
This approach leverages Nagios' configuration file to retrieve the necessary information and generate the desired report. You can adapt the script to suit your specific requirements or use it as a starting point for further customization.
taylorgodiva28
Posts: 1
Joined: Thu Jun 01, 2023 11:07 pm
Contact:

Re: Nagios Server Cluster report

Post by taylorgodiva28 »

Thank you so much for this useful information!
LauraH
Posts: 2
Joined: Mon May 08, 2023 4:01 pm
Contact:

Re: Nagios Server Cluster report

Post by LauraH »

To generate a recurring report in Nagios Core 4.3.4 to list the servers within each pool, along with their IP addresses and state, you can utilize the Nagios Core's reporting capabilities and custom scripting. Here's a general approach you can follow:

Create a custom script: Write a script in a programming language of your choice (such as Python, Perl, or Bash) to extract the required information from Nagios Core. This script will query the Nagios Core's status information and format it into the desired JSON, CSV, or XML format.

Query Nagios Core status information: Within your script, use the Nagios Core's external command interface or the status data query tool (such as status.cgi) to retrieve the necessary information. You'll need to extract the pool names, associated servers' IP addresses, and their respective states.

Format the data: Once you have retrieved the required information, format it into the desired output format (JSON, CSV, or XML) within your script. Organize the data in a way that lists the pools, their servers' IP addresses, and their states accordingly.

Schedule recurring execution: Set up a recurring job using a scheduler like Cron (on Linux) or Task Scheduler (on Windows) to run your script at specified intervals. Configure it to generate the report automatically and save it to a specific location.

By following these steps, you'll have a custom script that can be scheduled to run at regular intervals, generating the desired report listing the servers within each pool, along with their IP addresses and states in the chosen format (JSON, CSV, or XML).

Note: The implementation details of the script will depend on your specific environment, programming language choice, and Nagios Core configuration. You may need to adapt and customize the steps accordingly to fit your needs.

[size] Tray cable[size]
DealsPaws
Posts: 1
Joined: Tue Dec 19, 2023 5:18 am
Contact:

Re: Nagios Server Cluster report

Post by DealsPaws »

Thank you for the suggestion. I'll give it a try.
Post Reply