Nagios XI Space Weather Plugin

Picture of Caleb DePaulis
Caleb DePaulis
An image of lots of python code.

The Nagios space weather plugin enables the monitoring of space weather metrics, detection services, NOAA alerts, and aurora forecasts for any location. This article outlines the plugin’s functionality, provides data examples, and demonstrates its use in Nagios XI. For more information on the importance of space weather monitoring, refer to this article here, which describes the different aspects of space weather to monitor and why they matter.

Understanding the Space Weather Plugin

The space weather plugin monitors a variety of solar and space-related phenomena that can impact Earth’s systems, offering critical insights for industries and individuals dependent on satellite communications, aviation, and power grids. It tracks solar flares, geomagnetic storms, radio outages, solar radiation, and coronal mass ejections (CMEs), all of which can disrupt technology and infrastructure. The plugin also measures solar wind speed and density, which influence how the solar wind interacts with Earth’s magnetosphere. Additionally, it monitors magnetic field components like Bt and Bz, aiding in the prediction of space weather disturbances that could affect our planet.

The plugin also uses the Kp index to assess global geomagnetic activity. The 3-day forecast feature provides users with the highest Kp value predicted in the upcoming 3-day period and when it occurs, helping them gauge the intensity of space weather activity. With features like the hemispheric power index for both the northern and southern hemispheres, it allows for region-specific monitoring. Aurora chances are calculated based on current solar activity, giving users further insight into space weather’s impact on Earth’s atmosphere. This tool helps users stay informed, enabling them to make timely decisions and prepare for potential disruptions caused by space weather.

How This Plugin Works

This plugin operates by accessing and processing online data, primarily sourced from NASA and NOAA. The data is typically retrieved from websites that provide JSON-formatted data, which allows the Python script to easily read and extract valuable information. For sources that are not formatted as JSON, the plugin uses a slightly more complex process to parse the data and make it readable for extracting the desired information. Once the data is collected, the plugin evaluates the values to determine if the current conditions are categorized as OK, WARNING, or CRITICAL.

Collecting the Data

The following code snippet demonstrates how the plugin retrieves solar wind speed data:

def check_wind_speed():
    url = "https://services.swpc.noaa.gov/products/solar-wind/plasma-2-hour.json" 
    try:
        response = requests.get(url)
        response.raise_for_status()  # Checks if the request was successful

        data = response.json()
        if not data or len(data) < 2:
            return None

        latest_entry = data[-1]
        wind_speed_value = latest_entry[2]  
        return wind_speed_value
    except requests.exceptions.HTTPError as e:
        print(f"HTTP error occurred: {e}")
    except Exception as e:
        print(f"An error occurred: {e}")
    return wind_speed_value

This function uses the requests module in Python to access a JSON file from NOAA. After confirming a successful connection, it extracts the most recent entry in the JSON file and retrieves the value at index 2, which corresponds to the solar wind speed. Below is an example of the JSON format returned by the API:

[
  [
    "time_tag",
    "density",
    "speed",
    "temperature"
  ],
  [
    "2025-02-06 17:59:00.000",
    "0.55",
    "482.3",
    "252385"
  ]
]

As shown, the first entry in the JSON file represents the field labels (time, density, speed, and temperature), while the second entry contains the latest data, including the solar wind speed, which is stored at index 2. This structure makes it very easy to extract the required data, allowing it to be compared against the warning and critical thresholds set by the user. By checking the wind speed value against these thresholds, the plugin can quickly determine if the space weather conditions are within acceptable limits or if they require attention.

Processing and Sending Data to Nagios XI

Once the values are collected from the data retrieval function, the next step is to determine the severity of the value and send the result to Nagios XI. The following code snippet demonstrates how the severity is assessed:

if args.wind_speed:
        warning_default = 400
        critical_default = 700
        if args.warning:
            warning_default = args.warning
        if args.critical:
            critical_default = args.critical
        wind_speed = check_wind_speed()
        if wind_speed == None:
            print("Wind speed not found.")
            exit(3)
        elif float(wind_speed) > critical_default:
            print(f"CRITICAL - Solar wind speed is HIGH: {wind_speed} km/s | WindSpeed={wind_speed};{warning_default};{critical_default};;")
            exit(2)
        elif float(wind_speed) > warning_default: 
            print(f"WARNING - Solar wind speed is MILD: {wind_speed} km/s | WindSpeed={wind_speed};{warning_default};{critical_default};;")
            exit(1) 
        else:
            print(f"OK - Solar wind speed is LOW: {wind_speed} km/s | WindSpeed={wind_speed};{warning_default};{critical_default};;")
            exit(0)

The first thing this block of code does is check if the wind speed argument has been passed through. Next, it sets either default values or user-defined values for the warning and critical thresholds, depending on what has been specified. After that, it calls the check_wind_speed() function and compares the value to the defined thresholds within the if statements. Based on the comparison, it sends a message and an exit status code to Nagios XI for interpretation. The last part of the message is separated by a pipe (|), and it is formatted like this: <Value_Name>=<Value>;<Warning_Threshold>;<Critical_Threshold>;;. This format allows Nagios XI to graph the chosen value over time, facilitating the monitoring and alerting of space weather conditions.

How it Looks in Nagios

Now that you understand how the code works, let’s take a look at how it appears in Nagios XI, along with an example of the graphs generated by Nagios:

An Image showing a list of services from the space weather plugin on Nagios XI.
Image of Solar Wind Graph

The space weather plugin offers a wide range of metrics and detection services, allowing you to monitor the specific conditions that best fit your needs. As shown in the images above, all the data is conveniently centralized in one place, making it easier to access than browsing multiple websites. Additionally, it provides visualizations through graphs, enabling you to easily spot trends in space weather activity.

Conclusion

The Nagios space weather plugin offers a powerful solution for monitoring and managing space weather conditions that can impact various technologies and industries. By providing real-time data on solar activity, including solar wind speed, geomagnetic storms, and aurora forecasts, it enables users to stay informed and make proactive decisions. The integration with Nagios XI allows for seamless alerting and graphical representation of key metrics, ensuring that space weather disruptions are quickly identified and addressed. With this plugin, organizations can enhance their preparedness and response to space weather events, safeguarding critical infrastructure and operations.

Install the Plugin

To get started with the plugin, simply visit Nagios Enterprises GitHub repository and download the ZIP file. Once downloaded, open Nagios in your browser, navigate to Admin > System Extensions > Manage Config Wizards, then click Browse and upload the file. This will add the wizard and plugin to your Nagios instance and get you set up to monitor space weather conditions. To learn more about the wizard before using it, press here.

If you’d like to create your own plugin click the link here for a tutorial using bash, or if you’d prefer a video watch the video below to get a better understanding of how creating and configuring plugins work.

Share

Table of Contents