BotaxWebshell
Server IP : 68.178.172.28  /  Your IP : 216.73.216.26
Web Server : Apache
System : Linux 28.172.178.68.host.secureserver.net 4.18.0-553.89.1.el8_10.x86_64 #1 SMP Mon Dec 8 03:53:08 EST 2025 x86_64
User : kiskarnal ( 1003)
PHP Version : 8.0.30
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : ON |  Sudo : ON |  Pkexec : ON
Directory :  /usr/lib/fm-agent/plugins/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /usr/lib/fm-agent/plugins/ping.py
import agent_util
import sys
import os
import time
import string
import re


class PingPlugin(agent_util.Plugin):
    textkey = "agent_ping"
    label = "Agent Ping"

    @classmethod
    def get_metadata(self, config):
        status = agent_util.SUPPORTED
        msg = None

        data = {
            "ping_status": {
                "label": "Ping status",
                "options": None,
                "option_string": True,
                "status": status,
                "error_message": msg,
                "unit": "boolean",
            },
            "ping_packet_loss": {
                "label": "Ping packet loss",
                "options": None,
                "option_string": True,
                "status": status,
                "error_message": msg,
                "unit": "percent",
            },
            "ping_latency": {
                "label": "Ping latency",
                "options": None,
                "option_string": True,
                "status": status,
                "error_message": msg,
                "unit": "ms",
            },
        }

        return data

    def check(self, textkey, option, config):
        ping_binary_path = agent_util.which("ping")

        ping_timeout = 5.0
        if "darwin" in sys.platform.lower():
            ping_timeout = 5000.0

        if textkey == "ping_status":
            ret, output = agent_util.execute_command(
                "%s -c 1 -W %s %s" % (ping_binary_path, ping_timeout, option)
            )
            if not ret:
                return 1
            else:
                return None
        elif textkey == "ping_packet_loss":
            ret, output = agent_util.execute_command(
                "%s -c 10 -i 0.2 -W %s %s 2> /dev/null"
                % (ping_binary_path, ping_timeout * 2, option)
            )

            for line in output.split("/n"):
                if "packet loss" in line:
                    pl = float(
                        re.search(r"([-+]?\d*\.\d+|\d+)% packet loss", line).group(1)
                    )
                    return pl

            # if no match, default to 100% packet loss
            return 100.0

        elif textkey == "ping_latency":
            ret, output = agent_util.execute_command(
                "%s -c 1 -W %s %s" % (ping_binary_path, ping_timeout, option)
            )
            for line in output.split("/n"):
                if "time" in line:
                    rt = float(re.search(r"time=([-+]?\d*\.\d+|\d+) ms", line).group(1))
                    return rt

            # if no match, default to 0 ms
            return None
        else:
            return None

Youez - 2016 - github.com/yon3zu
LinuXploit