#wip: Python fixed and VBS in doing.
This commit is contained in:
parent
2f4a5d4609
commit
e245bbdfab
@ -48,7 +48,11 @@
|
||||
},
|
||||
"default_routes" : [
|
||||
"post:/agents/debian/{key} debian@agents",
|
||||
"post:/agents/windows/{key} windows@agents",
|
||||
"get:/agents/test/{key} test@agents",
|
||||
"get:/ /Public"
|
||||
]
|
||||
],
|
||||
"dispatchers" : {
|
||||
"agents" : "agents_dispatcher"
|
||||
}
|
||||
}
|
||||
@ -29,7 +29,23 @@ class AgentsController(ControllerAbstract):
|
||||
print([hostnames, domain, interfaces, disks, iterations, candle_times, cpu, memory, net_use])
|
||||
|
||||
def windows(self:Self, request:RequestModel, response:ResponseModel) -> None:
|
||||
pass
|
||||
|
||||
key:str = request.get("key")
|
||||
hostnames:list[str]
|
||||
domain:str|None
|
||||
interfaces:list[str]
|
||||
disks:list[list[str, int, int]]
|
||||
iterations:int
|
||||
candle_times:list[int, int]
|
||||
cpu:list[float, float, float, float, float]
|
||||
memory:list[int, int, int, int, int, float]
|
||||
net_use:list[list[list[str, int, int, int, int, int, int]]] = []
|
||||
|
||||
print(Utils.json_decode(request.body))
|
||||
|
||||
hostnames, domain, interfaces, disks, candle_times, iterations, cpu, memory = Utils.json_decode(request.body)
|
||||
|
||||
print([hostnames, domain, interfaces, disks, iterations, candle_times, cpu, memory, net_use])
|
||||
|
||||
def test(self:Self, request:RequestModel, response:ResponseModel) -> None:
|
||||
response.set_data({
|
||||
|
||||
13
Python/Dispatchers/AgentsDispatcher.py
Normal file
13
Python/Dispatchers/AgentsDispatcher.py
Normal file
@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from typing import Self
|
||||
from Interfaces.Application.NucelarMonitorInterface import NucelarMonitorInterface
|
||||
|
||||
class AgentsDispatcher:
|
||||
|
||||
def __init__(self:Self, nucelar_monitor:NucelarMonitorInterface) -> None:
|
||||
super().__init__(nucelar_monitor)
|
||||
|
||||
def save(self:Self) -> None:
|
||||
pass
|
||||
@ -4,7 +4,6 @@
|
||||
from typing import Any, Self, Optional, Sequence
|
||||
from threading import Thread
|
||||
from socket import socket as Socket, AF_INET, SOCK_STREAM, SOL_SOCKET, SO_REUSEADDR, SHUT_RDWR
|
||||
from requests import get as get
|
||||
from Interfaces.Application.NucelarMonitorInterface import NucelarMonitorInterface
|
||||
from Abstracts.WebServerAbstract import WebServerAbstract
|
||||
from Models.ResponseModel import ResponseModel
|
||||
|
||||
@ -30,12 +30,12 @@ class DispatchersManager:
|
||||
for subinputs in self.nucelar_monitor.files.load_json(inputs):
|
||||
|
||||
key:str
|
||||
controller:DispatcherAbstract|str
|
||||
dispatcher:DispatcherAbstract|str
|
||||
|
||||
for key, controller in subinputs.items():
|
||||
if isinstance(controller, str):
|
||||
controller = self.nucelar_monitor.models.get(DispatcherAbstract, controller)(self.nucelar_monitor)
|
||||
if controller is not None and isinstance(controller, DispatcherAbstract) and (
|
||||
for key, dispatcher in subinputs.items():
|
||||
if isinstance(dispatcher, str):
|
||||
dispatcher = self.nucelar_monitor.models.get(DispatcherAbstract, dispatcher)(self.nucelar_monitor)
|
||||
if dispatcher is not None and isinstance(dispatcher, DispatcherAbstract) and (
|
||||
overwrite or key not in self.__dispatcher
|
||||
):
|
||||
self.__dispatcher[key] = controller
|
||||
self.__dispatcher[key] = dispatcher
|
||||
@ -6,12 +6,14 @@ from Application.NucelarMonitor import NucelarMonitor
|
||||
from Controllers.AgentsController import AgentsController
|
||||
from Drivers.SQLServerDriver import SQLServerDriver
|
||||
from Drivers.WebServerDriver import WebServerDriver
|
||||
from Dispatchers.AgentsDispatcher import AgentsDispatcher
|
||||
|
||||
inputs:dict[str, dict[str, Any|None]] = {
|
||||
"default_models" : {
|
||||
"agents" : AgentsController,
|
||||
"sql_server" : SQLServerDriver,
|
||||
"web_server" : WebServerDriver
|
||||
"web_server" : WebServerDriver,
|
||||
"agents_dispatcher" : AgentsDispatcher,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,3 @@
|
||||
@echo off
|
||||
|
||||
:bucle
|
||||
cscript //nologo ..\VisualBasicScripts\NucelarMonitor.vbs
|
||||
@ping 127.255.255.255 -n 1 -w 5000 >nul
|
||||
goto bucle
|
||||
@rem @echo off
|
||||
cd %~dp0..\Python
|
||||
python3 run.py
|
||||
6
VisualBasicScripts/NucelarMonitor.bat
Normal file
6
VisualBasicScripts/NucelarMonitor.bat
Normal file
@ -0,0 +1,6 @@
|
||||
@echo off
|
||||
|
||||
:bucle
|
||||
cscript //nologo .\NucelarMonitor.vbs
|
||||
@ping 127.255.255.255 -n 1 -w 5000 >nul
|
||||
goto bucle
|
||||
@ -10,7 +10,7 @@ Dim memory_maximum, memory_minimum, memory_average, memory_in, memory_out, memor
|
||||
key = "pc_miguel"
|
||||
print_json = True
|
||||
send_data = False
|
||||
url_target = ""
|
||||
url_target = "http://127.0.0.1:13000/agents/windows/" & key
|
||||
ips = ""
|
||||
disks_info = ""
|
||||
start_date = DateDiff("s", #1/1/1970#, Now)
|
||||
@ -34,12 +34,13 @@ For Each item In wmi_service.ExecQuery("SELECT Name, Domain FROM Win32_ComputerS
|
||||
hostnames = hostnames & """" & item.Name & """"
|
||||
Next
|
||||
|
||||
For Each item In wmi_service.ExecQuery("SELECT IPAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
|
||||
For Each item In wmi_service.ExecQuery("SELECT NetConnectionID, IPAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
|
||||
If Not IsNull(item.IPAddress) Then
|
||||
If ips <> "" Then ips = ips & "," End If
|
||||
ips = ips & """" & item.IPAddress(0) & """"
|
||||
ips = ips & "[""" & item.NetConnectionID(0) & """, """ & item.IPAddress(0) & """]"
|
||||
End If
|
||||
Next
|
||||
ips = "[" & ips & "]"
|
||||
|
||||
For Each item In wmi_service.ExecQuery("SELECT DeviceID, Size, FreeSpace FROM Win32_LogicalDisk where DriveType = 3")
|
||||
|
||||
@ -99,12 +100,12 @@ if cpu_summatory <> 0 and iterations <> 0 Then cpu_average = Replace(CStr(cpu_su
|
||||
If memory_summatory <> 0 and iterations <> 0 Then memory_average = Round(memory_summatory / iterations) End If
|
||||
|
||||
json = "["
|
||||
json = json & """" & key & ""","
|
||||
' json = json & """" & key & ""","
|
||||
json = json & "[" & hostnames & "],""" & domain & """,[" & ips & "],[" & disks_info & "],"
|
||||
json = json & "[" & start_date & "," & DateDiff("s", #1/1/1970#, Now) & "],"
|
||||
json = json & iterations & ","
|
||||
json = json & "[" & cpu_in & "," & cpu_out & "," & cpu_minimum & "," & cpu_maximum & "," & cpu_average & "]"
|
||||
json = json & "[" & total_memory & "," & memory_in & "," & memory_out & "," & memory_minimum & "," & memory_maximum & "," & memory_average & "]"
|
||||
'json = json & "[" & start_date & "," & DateDiff("s", #1/1/1970#, Now) & "],"
|
||||
'json = json & iterations & ","
|
||||
'json = json & "[" & cpu_in & "," & cpu_out & "," & cpu_minimum & "," & cpu_maximum & "," & cpu_average & "]"
|
||||
'json = json & "[" & total_memory & "," & memory_in & "," & memory_out & "," & memory_minimum & "," & memory_maximum & "," & memory_average & "]"
|
||||
json = json & "]"
|
||||
|
||||
if print_json Then
|
||||
|
||||
63
VisualBasicScripts/tests.vbs
Normal file
63
VisualBasicScripts/tests.vbs
Normal file
@ -0,0 +1,63 @@
|
||||
Option Explicit
|
||||
On Error Resume Next
|
||||
|
||||
Dim strComputer, objWMIService, colConfigs, objConfig, colAdapters, objAdapter, strNombre, strIP, strSubnet, strTipo, strMascaraBits, i
|
||||
|
||||
strComputer = "."
|
||||
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
|
||||
|
||||
' Consultamos las configuraciones que tienen IP habilitada
|
||||
Set colConfigs = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
|
||||
|
||||
For Each objConfig In colConfigs
|
||||
' 1. Obtener el Nombre de la Interfaz (NetConnectionID)
|
||||
Set colAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter Where DeviceID = " & objConfig.Index)
|
||||
strNombre = "N/A"
|
||||
For Each objAdapter In colAdapters
|
||||
strNombre = objAdapter.NetConnectionID
|
||||
Next
|
||||
|
||||
' 2. Procesar cada dirección IP del adaptador
|
||||
If Not IsNull(objConfig.IPAddress) Then
|
||||
For i = 0 To UBound(objConfig.IPAddress)
|
||||
strIP = objConfig.IPAddress(i)
|
||||
strSubnet = objConfig.IPSubnet(i)
|
||||
|
||||
' 3. Verificar si es IPv6 (buscando el símbolo ":")
|
||||
If InStr(strIP, ":") > 0 Then
|
||||
strTipo = "IPv6"
|
||||
strMascaraBits = strSubnet ' En IPv6, WMI ya devuelve el prefijo (ej: 64)
|
||||
Else
|
||||
strTipo = "IPv4"
|
||||
strMascaraBits = MascaraABits(strSubnet)
|
||||
End If
|
||||
|
||||
' Salida de datos
|
||||
WScript.Echo "Interfaz: " & strNombre
|
||||
WScript.Echo "Tipo: " & strTipo
|
||||
WScript.Echo "IP: " & strIP
|
||||
WScript.Echo "Máscara: /" & strMascaraBits
|
||||
WScript.Echo "------------------------------------------"
|
||||
Next
|
||||
End If
|
||||
Next
|
||||
|
||||
' Función para convertir máscara decimal (255.255.255.0) a bits (24)
|
||||
Function MascaraABits(strMask)
|
||||
Dim arrOctetos, intBits, octeto
|
||||
intBits = 0
|
||||
arrOctetos = Split(strMask, ".")
|
||||
For Each octeto In arrOctetos
|
||||
Select Case Int(octeto)
|
||||
Case 255: intBits = intBits + 8
|
||||
Case 254: intBits = intBits + 7
|
||||
Case 252: intBits = intBits + 6
|
||||
Case 248: intBits = intBits + 5
|
||||
Case 240: intBits = intBits + 4
|
||||
Case 224: intBits = intBits + 3
|
||||
Case 192: intBits = intBits + 2
|
||||
Case 128: intBits = intBits + 1
|
||||
End Select
|
||||
Next
|
||||
MascaraABits = intBits
|
||||
End Function
|
||||
Loading…
Reference in New Issue
Block a user