| Server IP : 68.178.202.69 / Your IP : 216.73.216.122 Web Server : Apache System : Linux 69.202.178.68.host.secureserver.net 3.10.0-1160.139.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Nov 3 13:30:41 UTC 2025 x86_64 User : ikioworld ( 1005) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /lib/fm-agent/plugins/ |
Upload File : |
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