feature: add uptime check for some miners, and fix a bug with get_mac on BOS.

This commit is contained in:
UpstreamData
2023-06-27 09:35:07 -06:00
parent bf3bd7c2b9
commit df3a080c9d
15 changed files with 158 additions and 2 deletions

View File

@@ -66,6 +66,7 @@ class MinerData:
Attributes: Attributes:
ip: The IP of the miner as a str. ip: The IP of the miner as a str.
datetime: The time and date this data was generated. datetime: The time and date this data was generated.
uptime: The uptime of the miner in seconds.
mac: The MAC address of the miner as a str. mac: The MAC address of the miner as a str.
model: The model of the miner as a str. model: The model of the miner as a str.
make: The make of the miner as a str. make: The make of the miner as a str.
@@ -101,6 +102,7 @@ class MinerData:
ip: str ip: str
datetime: datetime = None datetime: datetime = None
uptime: int = 0
mac: str = "00:00:00:00:00:00" mac: str = "00:00:00:00:00:00"
model: str = "Unknown" model: str = "Unknown"
make: str = "Unknown" make: str = "Unknown"

View File

@@ -49,6 +49,10 @@ ANTMINER_MODERN_DATA_LOC = {
"cmd": "is_mining", "cmd": "is_mining",
"kwargs": {"web_get_conf": {"web": "get_miner_conf"}}, "kwargs": {"web_get_conf": {"web": "get_miner_conf"}},
}, },
"uptime": {
"cmd": "get_uptime",
"kwargs": {"api_stats": {"api": "stats"}},
},
} }
@@ -244,6 +248,19 @@ class AntminerModern(BMMiner):
except LookupError: except LookupError:
pass pass
async def get_uptime(self, api_stats: dict = None) -> Optional[int]:
if not api_stats:
try:
api_stats = await self.api.stats()
except APIError:
pass
if api_stats:
try:
return int(api_stats["STATS"][0]["Elapsed"])
except LookupError:
pass
ANTMINER_OLD_DATA_LOC = { ANTMINER_OLD_DATA_LOC = {
"mac": {"cmd": "get_mac", "kwargs": {}}, "mac": {"cmd": "get_mac", "kwargs": {}},
@@ -278,6 +295,10 @@ ANTMINER_OLD_DATA_LOC = {
"cmd": "is_mining", "cmd": "is_mining",
"kwargs": {"web_get_conf": {"web": "get_miner_conf"}}, "kwargs": {"web_get_conf": {"web": "get_miner_conf"}},
}, },
"uptime": {
"cmd": "get_uptime",
"kwargs": {"api_stats": {"api": "stats"}},
},
} }
@@ -471,3 +492,16 @@ class AntminerOld(CGMiner):
return True return True
else: else:
return False return False
async def get_uptime(self, api_stats: dict = None) -> Optional[int]:
if not api_stats:
try:
api_stats = await self.api.stats()
except APIError:
pass
if api_stats:
try:
return int(api_stats["STATS"][0]["Elapsed"])
except LookupError:
pass

View File

@@ -45,6 +45,7 @@ BFGMINER_DATA_LOC = {
"fault_light": {"cmd": "get_fault_light", "kwargs": {}}, "fault_light": {"cmd": "get_fault_light", "kwargs": {}},
"pools": {"cmd": "get_pools", "kwargs": {"api_pools": {"api": "pools"}}}, "pools": {"cmd": "get_pools", "kwargs": {"api_pools": {"api": "pools"}}},
"is_mining": {"cmd": "is_mining", "kwargs": {}}, "is_mining": {"cmd": "is_mining", "kwargs": {}},
"uptime": {"cmd": "get_uptime", "kwargs": {}},
} }
@@ -322,3 +323,6 @@ class BFGMiner(BaseMiner):
async def is_mining(self, *args, **kwargs) -> Optional[bool]: async def is_mining(self, *args, **kwargs) -> Optional[bool]:
return None return None
async def get_uptime(self, *args, **kwargs) -> Optional[int]:
return None

View File

@@ -48,6 +48,7 @@ GOLDSHELL_DATA_LOC = {
"fault_light": {"cmd": "get_fault_light", "kwargs": {}}, "fault_light": {"cmd": "get_fault_light", "kwargs": {}},
"pools": {"cmd": "get_pools", "kwargs": {"api_pools": {"api": "pools"}}}, "pools": {"cmd": "get_pools", "kwargs": {"api_pools": {"api": "pools"}}},
"is_mining": {"cmd": "is_mining", "kwargs": {}}, "is_mining": {"cmd": "is_mining", "kwargs": {}},
"uptime": {"cmd": "get_uptime", "kwargs": {}},
} }
@@ -161,3 +162,6 @@ class BFGMinerGoldshell(BFGMiner):
async def is_mining(self, *args, **kwargs) -> Optional[bool]: async def is_mining(self, *args, **kwargs) -> Optional[bool]:
return None return None
async def get_uptime(self, *args, **kwargs) -> Optional[int]:
return None

View File

@@ -46,6 +46,10 @@ BMMINER_DATA_LOC = {
"fault_light": {"cmd": "get_fault_light", "kwargs": {}}, "fault_light": {"cmd": "get_fault_light", "kwargs": {}},
"pools": {"cmd": "get_pools", "kwargs": {"api_pools": {"api": "pools"}}}, "pools": {"cmd": "get_pools", "kwargs": {"api_pools": {"api": "pools"}}},
"is_mining": {"cmd": "is_mining", "kwargs": {}}, "is_mining": {"cmd": "is_mining", "kwargs": {}},
"uptime": {
"cmd": "get_uptime",
"kwargs": {"api_stats": {"api": "stats"}},
},
} }
@@ -356,3 +360,16 @@ class BMMiner(BaseMiner):
async def is_mining(self, *args, **kwargs) -> Optional[bool]: async def is_mining(self, *args, **kwargs) -> Optional[bool]:
return None return None
async def get_uptime(self, api_stats: dict = None) -> Optional[int]:
if not api_stats:
try:
api_stats = await self.web.get_miner_conf()
except APIError:
pass
if api_stats:
try:
return int(api_stats["STATS"][0]["Elapsed"])
except LookupError:
pass

View File

@@ -176,6 +176,10 @@ BOSMINER_DATA_LOC = {
"cmd": "is_mining", "cmd": "is_mining",
"kwargs": {"api_tunerstatus": {"api": "tunerstatus"}}, "kwargs": {"api_tunerstatus": {"api": "tunerstatus"}},
}, },
"uptime": {
"cmd": "get_uptime",
"kwargs": {"api_summary": {"api": "summary"}},
},
} }
@@ -382,6 +386,8 @@ class BOSMiner(BaseMiner):
except APIError: except APIError:
pass pass
print(web_net_conf)
if isinstance(web_net_conf, dict): if isinstance(web_net_conf, dict):
if "/cgi-bin/luci/admin/network/iface_status/lan" in web_net_conf.keys(): if "/cgi-bin/luci/admin/network/iface_status/lan" in web_net_conf.keys():
web_net_conf = web_net_conf[ web_net_conf = web_net_conf[
@@ -1040,3 +1046,16 @@ class BOSMiner(BaseMiner):
return running return running
except LookupError: except LookupError:
pass pass
async def get_uptime(self, api_summary: dict = None) -> Optional[int]:
if not api_summary:
try:
api_summary = await self.api.summary()
except APIError:
pass
if api_summary:
try:
return int(api_summary["SUMMARY"][0]["Elapsed"])
except LookupError:
pass

View File

@@ -153,3 +153,6 @@ class BOSMinerOld(BOSMiner):
async def is_mining(self, *args, **kwargs) -> Optional[bool]: async def is_mining(self, *args, **kwargs) -> Optional[bool]:
return None return None
async def get_uptime(self, *args, **kwargs) -> Optional[int]:
return None

View File

@@ -89,6 +89,10 @@ BTMINER_DATA_LOC = {
}, },
"pools": {"cmd": "get_pools", "kwargs": {"api_pools": {"api": "pools"}}}, "pools": {"cmd": "get_pools", "kwargs": {"api_pools": {"api": "pools"}}},
"is_mining": {"cmd": "is_mining", "kwargs": {"api_status": {"api": "status"}}}, "is_mining": {"cmd": "is_mining", "kwargs": {"api_status": {"api": "status"}}},
"uptime": {
"cmd": "get_uptime",
"kwargs": {"api_summary": {"api": "summary"}},
},
} }
@@ -636,3 +640,16 @@ class BTMiner(BaseMiner):
return True if api_status["Msg"]["mineroff"] == "false" else False return True if api_status["Msg"]["mineroff"] == "false" else False
except LookupError: except LookupError:
pass pass
async def get_uptime(self, api_summary: dict = None) -> Optional[int]:
if not api_summary:
try:
api_summary = await self.api.summary()
except APIError:
pass
if api_summary:
try:
return int(api_summary["SUMMARY"][0]["Elapsed"])
except LookupError:
pass

View File

@@ -46,6 +46,10 @@ CGMINER_DATA_LOC = {
"fault_light": {"cmd": "get_fault_light", "kwargs": {}}, "fault_light": {"cmd": "get_fault_light", "kwargs": {}},
"pools": {"cmd": "get_pools", "kwargs": {"api_pools": {"api": "pools"}}}, "pools": {"cmd": "get_pools", "kwargs": {"api_pools": {"api": "pools"}}},
"is_mining": {"cmd": "is_mining", "kwargs": {}}, "is_mining": {"cmd": "is_mining", "kwargs": {}},
"uptime": {
"cmd": "get_uptime",
"kwargs": {"api_stats": {"api": "stats"}},
},
} }
@@ -379,3 +383,16 @@ class CGMiner(BaseMiner):
async def is_mining(self, *args, **kwargs) -> Optional[bool]: async def is_mining(self, *args, **kwargs) -> Optional[bool]:
return None return None
async def get_uptime(self, api_stats: dict = None) -> Optional[int]:
if not api_stats:
try:
api_stats = await self.api.stats()
except APIError:
pass
if api_stats:
try:
return int(api_stats["STATS"][0]["Elapsed"])
except LookupError:
pass

View File

@@ -51,6 +51,7 @@ AVALON_DATA_LOC = {
}, },
"pools": {"cmd": "get_pools", "kwargs": {"api_pools": {"api": "pools"}}}, "pools": {"cmd": "get_pools", "kwargs": {"api_pools": {"api": "pools"}}},
"is_mining": {"cmd": "is_mining", "kwargs": {}}, "is_mining": {"cmd": "is_mining", "kwargs": {}},
"uptime": {"cmd": "get_uptime", "kwargs": {}},
} }

View File

@@ -89,6 +89,10 @@ LUXMINER_DATA_LOC = {
"cmd": "is_mining", "cmd": "is_mining",
"kwargs": {}, "kwargs": {},
}, },
"uptime": {
"cmd": "get_uptime",
"kwargs": {"api_stats": {"api": "stats"}},
},
} }
@@ -429,3 +433,16 @@ class LUXMiner(BaseMiner):
async def is_mining(self) -> Optional[bool]: async def is_mining(self) -> Optional[bool]:
pass pass
async def get_uptime(self, api_stats: dict = None) -> Optional[int]:
if not api_stats:
try:
api_stats = await self.api.stats()
except APIError:
pass
if api_stats:
try:
return int(api_stats["STATS"][0]["Elapsed"])
except LookupError:
pass

View File

@@ -44,6 +44,7 @@ VNISH_DATA_LOC = {
"fault_light": {"cmd": "get_fault_light", "kwargs": {}}, "fault_light": {"cmd": "get_fault_light", "kwargs": {}},
"pools": {"cmd": "get_pools", "kwargs": {"api_pools": {"api": "pools"}}}, "pools": {"cmd": "get_pools", "kwargs": {"api_pools": {"api": "pools"}}},
"is_mining": {"cmd": "is_mining", "kwargs": {}}, "is_mining": {"cmd": "is_mining", "kwargs": {}},
"uptime": {"cmd": "get_uptime", "kwargs": {}},
} }
@@ -173,3 +174,6 @@ class VNish(BMMiner):
async def is_mining(self, *args, **kwargs) -> Optional[bool]: async def is_mining(self, *args, **kwargs) -> Optional[bool]:
return None return None
async def get_uptime(self, *args, **kwargs) -> Optional[int]:
return None

View File

@@ -354,6 +354,15 @@ class BaseMiner(ABC):
""" """
pass pass
@abstractmethod
async def get_uptime(self, *args, **kwargs) -> Optional[int]:
"""Get the uptime of the miner in seconds.
Returns:
The uptime of the miner in seconds.
"""
pass
async def _get_data(self, allow_warning: bool, data_to_get: list = None) -> dict: async def _get_data(self, allow_warning: bool, data_to_get: list = None) -> dict:
if not data_to_get: if not data_to_get:
# everything # everything
@@ -375,6 +384,7 @@ class BaseMiner(ABC):
"fault_light", "fault_light",
"pools", "pools",
"is_mining", "is_mining",
"uptime",
] ]
api_multicommand = [] api_multicommand = []
web_multicommand = [] web_multicommand = []

View File

@@ -151,6 +151,9 @@ class UnknownMiner(BaseMiner):
async def is_mining(self, *args, **kwargs) -> Optional[bool]: async def is_mining(self, *args, **kwargs) -> Optional[bool]:
return None return None
async def get_uptime(self, *args, **kwargs) -> Optional[int]:
return None
async def get_data( async def get_data(
self, allow_warning: bool = False, data_to_get: list = None self, allow_warning: bool = False, data_to_get: list = None
) -> MinerData: ) -> MinerData:

View File

@@ -141,7 +141,11 @@ class BOSMinerWebAPI(BaseWebAPI):
try: try:
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
await self.luci_auth(client) await self.luci_auth(client)
data = await client.get(f"http://{self.ip}{path}") data = await client.get(
f"http://{self.ip}{path}", headers={"User-Agent": "BTC Tools v0.1"}
)
print(data.status_code)
print(data.text)
if data.status_code == 200: if data.status_code == 200:
return data.json() return data.json()
if ignore_errors: if ignore_errors:
@@ -161,7 +165,7 @@ class BOSMinerWebAPI(BaseWebAPI):
"User-Agent": "BTC Tools v0.1", # only seems to respond if this user-agent is set "User-Agent": "BTC Tools v0.1", # only seems to respond if this user-agent is set
"Content-Type": "application/x-www-form-urlencoded", "Content-Type": "application/x-www-form-urlencoded",
} }
d = await session.post(url, headers=headers, data=login) await session.post(url, headers=headers, data=login)
async def get_net_conf(self): async def get_net_conf(self):
return await self.send_luci_command( return await self.send_luci_command(