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 · 1 comment
Open

Problem with external plugin #91

Foxconn11 opened this issue Dec 26, 2023 · 1 comment

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()

@julian3
Copy link

julian3 commented Nov 6, 2024

I compared the output of my plugin with yours and I noted two things. To make the plugin work in Windows, after doing my reasearch, I found out I had to output a dot as the last line, for both the config and the values output.

  1. Output ending with a dot:
C:\Program Files (x86)\Munin Node for Windows\plugin>muninstats.exe config
graph_title Server3 DB Connections
graph_vlabel number
graph_args --base 1000 -l 0
graph_scale no
graph_category appserver
graph_info The number of opened and closed connections on the web platform
conn_opened.label opened
conn_closed.label closed
.
  1. Config output ending with a dot:
C:\Program Files (x86)\Munin Node for Windows\plugin>muninstats.exe
conn_opened.value 0
conn_closed.value 0
.

And that's for the output side of the plugin. For what regards configuring the plugin in munin-node's config file try these two things:

a) To avoid problems I put the plugin code under munin-node's plugin folder, in my case it's C:\Program Files (x86)\Munin Node for Windows\plugin. Do this to avoid, you never know, permission or security problems arising by using other folders/drives. Obviously adapt the path to the one on your system, if you're not sure where munin-node is installed just open Services and you'll find the full path.

b) Use a single command to declare your plugin in munin-node.ini. For e.g. I had problems passing parameters so I realized that I had to use a single command. This is my config:

[ExternalPlugin]
Plugin01=C:\Program Files (x86)\Munin Node for Windows\plugin\MuninStats.exe

In your case try changing your configuration line (Plugin01="python W:\sat2.py") to this (no double quotes):

Plugin01=C:\Program Files (x86)\Munin Node for Windows\plugin\runSat2.bat

and runSat2.bat will contain the following:

python W:\sat2.py

Be sure that python.exe is reachable by adding python's executable folder to the PATH environment and check it on the command line running the command SET PATH.

Hope this helps.

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

2 participants