Compare commits
	
		
			3 Commits
		
	
	
		
			8df189aa22
			...
			134f59f9ee
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 134f59f9ee | |||
| 54373c5bec | |||
| 7378affcb5 | 
@@ -52,9 +52,15 @@ def getNodeInformation(zkhandler, node_name):
 | 
			
		||||
    node_running_domains = zkhandler.read(("node.running_domains", node_name)).split()
 | 
			
		||||
    try:
 | 
			
		||||
        node_health = int(zkhandler.read(("node.monitoring.health", node_name)))
 | 
			
		||||
    except ValueError:
 | 
			
		||||
    except Exception:
 | 
			
		||||
        node_health = "N/A"
 | 
			
		||||
    node_health_plugins = zkhandler.read(("node.monitoring.plugins", node_name)).split()
 | 
			
		||||
    try:
 | 
			
		||||
        node_health_plugins = zkhandler.read(
 | 
			
		||||
            ("node.monitoring.plugins", node_name)
 | 
			
		||||
        ).split()
 | 
			
		||||
    except Exception:
 | 
			
		||||
        node_health_plugins = list()
 | 
			
		||||
 | 
			
		||||
    node_health_details = list()
 | 
			
		||||
    for plugin in node_health_plugins:
 | 
			
		||||
        plugin_last_run = zkhandler.read(
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										103
									
								
								node-daemon/plugins/edac
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								node-daemon/plugins/edac
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,103 @@
 | 
			
		||||
#!/usr/bin/env python3
 | 
			
		||||
 | 
			
		||||
# edac.py - PVC Monitoring example plugin for EDAC
 | 
			
		||||
# Part of the Parallel Virtual Cluster (PVC) system
 | 
			
		||||
#
 | 
			
		||||
#    Copyright (C) 2018-2022 Joshua M. Boniface <joshua@boniface.me>
 | 
			
		||||
#
 | 
			
		||||
#    This program is free software: you can redistribute it and/or modify
 | 
			
		||||
#    it under the terms of the GNU General Public License as published by
 | 
			
		||||
#    the Free Software Foundation, version 3.
 | 
			
		||||
#
 | 
			
		||||
#    This program is distributed in the hope that it will be useful,
 | 
			
		||||
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
#    GNU General Public License for more details.
 | 
			
		||||
#
 | 
			
		||||
#    You should have received a copy of the GNU General Public License
 | 
			
		||||
#    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
#
 | 
			
		||||
###############################################################################
 | 
			
		||||
 | 
			
		||||
# This script provides an example of a PVC monitoring plugin script. It will create
 | 
			
		||||
# a simple plugin to check the system's EDAC registers and report any failures.
 | 
			
		||||
 | 
			
		||||
# This script can thus be used as an example or reference implementation of a
 | 
			
		||||
# PVC monitoring pluginscript and expanded upon as required.
 | 
			
		||||
 | 
			
		||||
# A monitoring plugin script must implement the class "MonitoringPluginScript" which
 | 
			
		||||
# extends "MonitoringPlugin", providing the 3 functions indicated. Detailed explanation
 | 
			
		||||
# of the role of each function is provided in context of the example; see the other
 | 
			
		||||
# examples for more potential uses.
 | 
			
		||||
 | 
			
		||||
# WARNING:
 | 
			
		||||
#
 | 
			
		||||
# This script will run in the context of the node daemon keepalives as root.
 | 
			
		||||
# DO NOT install untrusted, unvetted plugins under any circumstances.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# This import is always required here, as MonitoringPlugin is used by the
 | 
			
		||||
# MonitoringPluginScript class
 | 
			
		||||
from pvcnoded.objects.MonitoringInstance import MonitoringPlugin
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# A monitoring plugin script must always expose its nice name, which must be identical to
 | 
			
		||||
# the file name
 | 
			
		||||
PLUGIN_NAME = "edac"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# The MonitoringPluginScript class must be named as such, and extend MonitoringPlugin.
 | 
			
		||||
class MonitoringPluginScript(MonitoringPlugin):
 | 
			
		||||
    def setup(self):
 | 
			
		||||
        """
 | 
			
		||||
        setup(): Perform special setup steps during node daemon startup
 | 
			
		||||
 | 
			
		||||
        This step is optional and should be used sparingly.
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
        pass
 | 
			
		||||
 | 
			
		||||
    def run(self):
 | 
			
		||||
        """
 | 
			
		||||
        run(): Perform the check actions and return a PluginResult object
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
        # Run any imports first
 | 
			
		||||
        import daemon_lib.common as common
 | 
			
		||||
        from re import match, search
 | 
			
		||||
 | 
			
		||||
        # Get edac-util output
 | 
			
		||||
        retcode, stdout, stderr = common.run_os_command('/usr/bin/edac-util')
 | 
			
		||||
 | 
			
		||||
        # If there's no errors, we're OK
 | 
			
		||||
        if match(r'^edac-util: No errors to report.', stdout):
 | 
			
		||||
            health_delta = 0
 | 
			
		||||
            message = "EDAC reports no errors"
 | 
			
		||||
        else:
 | 
			
		||||
            health_delta = 0
 | 
			
		||||
            message = "EDAC reports errors: "
 | 
			
		||||
            errors = list()
 | 
			
		||||
            for line in stdout.split('\n'):
 | 
			
		||||
                if match(r'^mc[0-9]: csrow', line):
 | 
			
		||||
                    if 'Uncorrected' in line:
 | 
			
		||||
                        health_delta = 10
 | 
			
		||||
                    errors.append(' '.join(line.split()[2:]))
 | 
			
		||||
            message += ', '.join(errors)
 | 
			
		||||
 | 
			
		||||
        # Set the health delta in our local PluginResult object
 | 
			
		||||
        self.plugin_result.set_health_delta(health_delta)
 | 
			
		||||
 | 
			
		||||
        # Set the message in our local PluginResult object
 | 
			
		||||
        self.plugin_result.set_message(message)
 | 
			
		||||
 | 
			
		||||
        # Return our local PluginResult object
 | 
			
		||||
        return self.plugin_result
 | 
			
		||||
 | 
			
		||||
    def cleanup(self):
 | 
			
		||||
        """
 | 
			
		||||
        cleanup(): Perform special cleanup steps during node daemon termination
 | 
			
		||||
 | 
			
		||||
        This step is optional and should be used sparingly.
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
        pass
 | 
			
		||||
@@ -190,6 +190,8 @@ class MonitoringInstance(object):
 | 
			
		||||
        self.all_plugins = list()
 | 
			
		||||
        self.all_plugin_names = list()
 | 
			
		||||
 | 
			
		||||
        successful_plugins = 0
 | 
			
		||||
 | 
			
		||||
        # Load each plugin file into the all_plugins list
 | 
			
		||||
        for plugin_file in sorted(plugin_files):
 | 
			
		||||
            try:
 | 
			
		||||
@@ -211,8 +213,6 @@ class MonitoringInstance(object):
 | 
			
		||||
                    self.this_node,
 | 
			
		||||
                    plugin_script.PLUGIN_NAME,
 | 
			
		||||
                )
 | 
			
		||||
                self.all_plugins.append(plugin)
 | 
			
		||||
                self.all_plugin_names.append(plugin.plugin_name)
 | 
			
		||||
 | 
			
		||||
                # Create plugin key
 | 
			
		||||
                self.zkhandler.write(
 | 
			
		||||
@@ -273,6 +273,11 @@ class MonitoringInstance(object):
 | 
			
		||||
                        ),
 | 
			
		||||
                    ]
 | 
			
		||||
                )
 | 
			
		||||
 | 
			
		||||
                self.all_plugins.append(plugin)
 | 
			
		||||
                self.all_plugin_names.append(plugin.plugin_name)
 | 
			
		||||
                successful_plugins += 1
 | 
			
		||||
 | 
			
		||||
                self.logger.out(
 | 
			
		||||
                    f"Successfully loaded monitoring plugin '{plugin.plugin_name}'",
 | 
			
		||||
                    state="o",
 | 
			
		||||
@@ -292,6 +297,9 @@ class MonitoringInstance(object):
 | 
			
		||||
            ]
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        if successful_plugins < 1:
 | 
			
		||||
            return
 | 
			
		||||
 | 
			
		||||
        # Clean up any old plugin data for which a plugin file no longer exists
 | 
			
		||||
        for plugin_key in self.zkhandler.children(
 | 
			
		||||
            ("node.monitoring.data", self.this_node.name)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user