Nagios Server Cluster report
-
- Posts: 13
- Joined: Sat Feb 12, 2022 1:21 am
Nagios Server Cluster report
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.
-
- Posts: 2
- Joined: Thu Dec 29, 2022 3:21 am
Re: Nagios Server Cluster report
Great post I would like to thank you for the efforts you have made in writing this interesting and knowledgeable article.
-
- Posts: 1
- Joined: Fri Apr 21, 2023 1:54 pm
Re: Nagios Server Cluster report
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.
Re: Nagios Server Cluster report
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]
Agile Onboarding[size]
-
- Posts: 1
- Joined: Tue May 09, 2023 10:56 pm
- Contact:
Re: Nagios Server Cluster report
Thank you so much for the post
-
- Posts: 1
- Joined: Mon May 22, 2023 12:35 pm
Re: Nagios Server Cluster report
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.
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.