/
minecraft.py
52 lines (42 loc) · 1.29 KB
/
minecraft.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
try: import json
except ImportError: import simplejson as json
import agent_util
import datetime
from mcstatus import MinecraftServer
class MinecraftPlugin(agent_util.Plugin):
textkey = "minecraft"
label = "Minecraft"
@classmethod
def get_metadata(self, config):
status = agent_util.SUPPORTED
msg = None
if not True:
status = agent_util.MISCONFIGURED
msg = "The Minecraft plugin is not configured properly\nCheck for mcstatus Python module"
metadata = {
"players": {
"label": "Players online",
"options": None,
"status": status,
"error_message": msg,
},
"latency": {
"label": "Server latency",
"options": None,
"status": status,
"error_message": msg,
"unit": "ms"
}
}
return metadata
def check(self, textkey, data, config):
server = MinecraftServer.lookup("localhost:25565")
srv = server.status()
players = srv.players.online
latency = server.ping()
if textkey == 'players':
return players
elif textkey == 'latency':
return latency
return 0