Update auf Skills
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import json, os, socket, ssl, sys, time
|
||||
from urllib.request import Request, urlopen
|
||||
from urllib.error import HTTPError
|
||||
PROTO='jarvis.skill.invoke.v1'
|
||||
def fail(c,m): return {'protocol':PROTO,'success':False,'error':{'code':c,'message':m}}
|
||||
def ok(d,m='OK',mut=False): return {'protocol':PROTO,'success':True,'data':d,'message':m,'mutated':mut}
|
||||
def main(inv):
|
||||
a=inv.get('action'); x=inv.get('input') or {}
|
||||
if a=='tcp_check':
|
||||
t=time.perf_counter(); reachable=True
|
||||
try:
|
||||
with socket.create_connection((x['host'],int(x['port'])),timeout=float(x.get('timeout_seconds',3))): pass
|
||||
except OSError: reachable=False
|
||||
ms=(time.perf_counter()-t)*1000; return ok({'reachable':reachable,'latency_ms':round(ms,2)},'TCP-Prüfung abgeschlossen.')
|
||||
if a=='http_check':
|
||||
t=time.perf_counter(); status=0; reachable=False; verify=bool(x.get('verify_tls',True)); ctx=None
|
||||
if x['url'].startswith('https://') and not verify: ctx=ssl._create_unverified_context()
|
||||
try:
|
||||
with urlopen(Request(x['url'],headers={'User-Agent':'JARVIS-Skill/1'}),timeout=float(x.get('timeout_seconds',5)),context=ctx) as r: status=int(r.status); reachable=True
|
||||
except HTTPError as e: status=int(e.code); reachable=True
|
||||
except Exception: pass
|
||||
ms=(time.perf_counter()-t)*1000; return ok({'reachable':reachable,'status':status,'latency_ms':round(ms,2)},'HTTP-Prüfung abgeschlossen.')
|
||||
if a=='dns_lookup':
|
||||
vals=sorted({i[4][0] for i in socket.getaddrinfo(x['host'],None)}); return ok({'addresses':vals,'count':len(vals)},'DNS aufgelöst.')
|
||||
if a=='wake_on_lan':
|
||||
mac=''.join(c for c in x['mac'] if c.isalnum())
|
||||
if len(mac)!=12: return fail('INVALID_MAC','MAC-Adresse ungültig')
|
||||
packet=b'\xff'*6+bytes.fromhex(mac)*16; broad=x.get('broadcast') or os.getenv('WOL_BROADCAST','255.255.255.255'); port=int(x.get('port') or os.getenv('WOL_PORT','9'))
|
||||
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM); s.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,1); s.sendto(packet,(broad,port)); s.close()
|
||||
return ok({'sent':True,'broadcast':broad,'port':port},'Wake-on-LAN gesendet.',True)
|
||||
return fail('UNKNOWN_ACTION',f'Unbekannte Aktion: {a}')
|
||||
try: res=main(json.load(sys.stdin))
|
||||
except Exception as e: res=fail('NETWORK_TOOL_ERROR',str(e))
|
||||
json.dump(res,sys.stdout,ensure_ascii=False)
|
||||
@@ -0,0 +1,184 @@
|
||||
{
|
||||
"protocol": "jarvis.skill.v1",
|
||||
"id": "home.network-tools",
|
||||
"name": "Home Network Tools",
|
||||
"version": "1.0.0",
|
||||
"description": "Kleine Netzwerk-Werkzeuge für Erreichbarkeit, DNS und Wake-on-LAN.",
|
||||
"runtime": {
|
||||
"type": "process",
|
||||
"command": "python3",
|
||||
"args": [
|
||||
"main.py"
|
||||
],
|
||||
"timeout_ms": 10000,
|
||||
"env_from": [
|
||||
"WOL_BROADCAST",
|
||||
"WOL_PORT"
|
||||
]
|
||||
},
|
||||
"permissions": {
|
||||
"network": true,
|
||||
"system_exec": true
|
||||
},
|
||||
"actions": [
|
||||
{
|
||||
"name": "tcp_check",
|
||||
"description": "Prüft, ob ein TCP-Port erreichbar ist.",
|
||||
"input_schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"host": {
|
||||
"type": "string"
|
||||
},
|
||||
"port": {
|
||||
"type": "integer"
|
||||
},
|
||||
"timeout_seconds": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"host",
|
||||
"port"
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"output_schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"reachable": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"latency_ms": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"reachable",
|
||||
"latency_ms"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "http_check",
|
||||
"description": "Prüft einen HTTP/HTTPS-Endpunkt und misst die Antwortzeit.",
|
||||
"input_schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"url": {
|
||||
"type": "string"
|
||||
},
|
||||
"timeout_seconds": {
|
||||
"type": "number"
|
||||
},
|
||||
"verify_tls": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"url"
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"output_schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"reachable": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"status": {
|
||||
"type": "integer"
|
||||
},
|
||||
"latency_ms": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"reachable",
|
||||
"status",
|
||||
"latency_ms"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "dns_lookup",
|
||||
"description": "Löst einen Hostnamen in IP-Adressen auf.",
|
||||
"input_schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"host": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"host"
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"output_schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"addresses": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"count": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"addresses",
|
||||
"count"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "wake_on_lan",
|
||||
"description": "Sendet ein Wake-on-LAN Magic Packet an ein Gerät.",
|
||||
"mutates": true,
|
||||
"input_schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"mac": {
|
||||
"type": "string"
|
||||
},
|
||||
"broadcast": {
|
||||
"type": "string"
|
||||
},
|
||||
"port": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"mac"
|
||||
],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"output_schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"sent": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"broadcast": {
|
||||
"type": "string"
|
||||
},
|
||||
"port": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"sent",
|
||||
"broadcast",
|
||||
"port"
|
||||
],
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user