Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with external plugin #91

Open
Foxconn11 opened this issue Dec 26, 2023 · 0 comments
Open

Problem with external plugin #91

Foxconn11 opened this issue Dec 26, 2023 · 0 comments

Comments

@Foxconn11
Copy link

Foxconn11 commented Dec 26, 2023

Hey there,

i have written a external Plugin to get some values of a Text file (BDADataEx logs in a txt file)

if i try to get the values from the file it looks like this:

> python W:\sat2.py name
TBS_Signal
> python W:\sat2.py config

graph_title TBS
graph_args --base 1000 -l 0
graph_category custom
graph_vlabel Werte
lock.label Lock
level.label Level
quality.label Quality
snr.label SNR
rf_level.label RFLevel

> python W:\sat2.py

lock.value 1
level.value 73
quality.value 58
snr.value 11.7
rf_level.value -27

For me it looks right. Maybe it isn't.

I tried to add the Plugin in the External Plugin section in the munin-node.ini file like this:
Plugin01="python W:\sat2.py"
then when i call munin-node.exe it gives this output:
Loaded plugin [class ExternalMuninNodePlugin - TBS_Signal]

when i add like described:
Plugin01=W:\sat2.py
i get
ERROR:Failed to load External plugin: W:\sat2.py

Even if it says its loaded, it wouldn't generate any graphs.

Maybe someone knows what i did wrong.

Python file:

#!/usr/bin/env python

import re
import sys

def extract_data(file_path):
    try:
        with open(file_path, 'r') as file:
            # Lesen Sie alle Zeilen der Datei
            lines = file.readlines()

            # Extrahieren Sie die Daten aus der letzten Zeile mit einem regulären Ausdruck
            last_line = lines[-1]
            match = re.search(r'Lock: (\d+), Level: (\d+), Quality: (\d+), SNR: ([\d.]+)dB, BER: ([\d.]+), RFLevel: (-?\d+) dBm', last_line)

            if match:
                lock = int(match.group(1))
                level = int(match.group(2))
                quality = int(match.group(3))
                snr = float(match.group(4))
                rf_level = int(match.group(6))

                return {'Lock': lock, 'Level': level, 'Quality': quality, 'SNR': snr, 'RFLevel': rf_level}
            else:
                print("Die letzte Zeile der Datei entspricht nicht dem erwarteten Muster.")
                return None
    except Exception as e:
        print(f"Fehler beim Lesen der Datei: {e}")
        return None

def autoconf():
    # Diese Funktion wird von Munin aufgerufen, um zu überprüfen, ob das Plugin auf dem Zielrechner ausgeführt werden kann
    # Sie sollte 0 für "ja" und 1 für "nein" zurückgeben
    try:
        import re
        return 0
    except ImportError:
        return 1
        
def name():
    # Diese Funktion wird von Munin aufgerufen, um zu überprüfen, ob das Plugin auf dem Zielrechner ausgeführt werden kann
    # Sie sollte 0 für "ja" und 1 für "nein" zurückgeben
    print ("TBS_Signal")

def config():
    # Diese Funktion gibt die Konfiguration des Plugins aus, die Munin verwenden wird
    print("graph_title TBS")
    print("graph_args --base 1000 -l 0")
    print("graph_category custom")
    print("graph_vlabel Werte")
    print("lock.label Lock")
    print("level.label Level")
    print("quality.label Quality")
    print("snr.label SNR")
    print("rf_level.label RFLevel")
    sys.exit(0)

def fetch():
    # Diese Funktion wird von Munin aufgerufen, um die Daten zu sammeln und an Munin zu senden
    file_path = 'W:\\SignalStat.txt'  # Passe dies entsprechend an
    data = extract_data(file_path)

    if data:
        print(f"lock.value {data['Lock']}")
        print(f"level.value {data['Level']}")
        print(f"quality.value {data['Quality']}")
        print(f"snr.value {data['SNR']}")
        print(f"rf_level.value {data['RFLevel']}")
        sys.exit(0)
    else:
        sys.exit(1)

# Überprüfen, welches Subkommando Munin erwartet
if len(sys.argv) > 1 and sys.argv[1] == "autoconf":
    autoconf()
elif len(sys.argv) > 1 and sys.argv[1] == "config":
    config()
elif len(sys.argv) > 1 and sys.argv[1] == "name":
    name()
else:
    fetch()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant