def watch_get_all(self): msg = Message("WATCH_GET") msg.set_str('field_name', 'config_child') msg.set_array('field_value', ["0"]) return msg
def read_msg(self, data, offset): msg_headers = self.read_msg_header(data, offset) msg_header = msg_headers[0] msg_offset = msg_headers[1] msg = Message(msg_header[0]) for idx, field_name in enumerate(msg_header): if idx > 0: sigs = self.read_signature(data, msg_offset) sig = sigs[0] msg_offset = sigs[1] if sig == self.packet_type.INTEGER: rtn_ints = self.read_int(data, msg_offset) rtn_int = rtn_ints[0] msg_offset = rtn_ints[1] msg.set_int(field_name, rtn_int) elif sig == self.packet_type.FLOAT: rtn_floats = self.read_float(data, msg_offset) rtn_float = rtn_floats[0] msg_offset = rtn_floats[1] msg.set_float(field_name, rtn_float) elif sig == self.packet_type.LONG: rtn_longs = self.read_long(data, msg_offset) rtn_long = rtn_longs[0] msg_offset = rtn_longs[1] msg.set_long(field_name, rtn_long) elif sig == self.packet_type.STRING: rtn_strs = self.read_str(data, msg_offset) rtn_str = rtn_strs[0] msg_offset = rtn_strs[1] msg.set_str(field_name, rtn_str) elif sig == self.packet_type.BYTES: rtn_bins = self.read_bytes(data, msg_offset) rtn_bin = rtn_bins[0] msg_offset = rtn_bins[1] msg.set_bytes(field_name, rtn_bin) elif sig == self.packet_type.COMPLEX: rtn_msgs = self.read_msg(data, msg_offset) rtn_msg = rtn_msgs[0] msg_offset = rtn_msgs[1] msg.set_msg(field_name, rtn_msg) elif sig == self.packet_type.ARRAY: rtn_arrays = self.read_array(data, msg_offset) rtn_array = rtn_arrays[0] msg_offset = rtn_arrays[1] msg.set_array(field_name, rtn_array) return (msg, msg_offset)
def login(self): msg = Message("LOGIN") msg.set_str('user_id', 'root') msg.set_str('user_pw', 'changeit') msg.set_int('client_type', 6) return msg
def channel_get(self): objectId = self.readCommand('object id') msg = Message("CHANNEL_GET") msg.set_str('field_name', 'object_id') msg.set_array('field_value', [objectId]) return msg
def watch_get(self): objectId = self.readCommand('object id') msg = Message("WATCH_GET") msg.set_str('field_name', 'object_id') msg.set_array('field_value', [objectId]) return msg
def config_get(self): objectId = self.readCommand('object id') msg = Message("CONFIG_GET") msg.set_str('field_name', 'object_id') msg.set_array('field_value', [objectId]) return msg
def channel_get_all(self): msg = Message("CHANNEL_GET") msg.set_str('base_config_id', '0') msg.set_str('channel_type', '*') msg.set_str('field_name', 'list') msg.set_str('object_id', '*') msg.set_str('os', '*') msg.set_str('watch_type', '*') msg.set_array('field_value', []) return msg
def recv(self, socket): data_size = self.recv_header(socket) if data_size > -1: data = socket.recv(data_size + 4) tail = bytes(struct.unpack_from("!4s", data, data_size)[0]).decode() if tail != self.TAIL: raise TypeError("Error packet. invalid tail - %s" % tail) return PacketReader().parse_to_msg(data) return Message("DEFAULT")
def execute(self): msgResponse = Message(self.r_msg.get_name()) msgResponse.set_int("return_code", 1) msgResponse.set_int("current_nfiles", 2656) msgResponse.set_int("current_queue", 1) msgResponse.set_int("idle", 94) msgResponse.set_int("max_nfile", 381681) msgResponse.set_int("mem_buffer", 0) msgResponse.set_int("mem_cached", 2138) msgResponse.set_int("mem_free", 312) msgResponse.set_int("mem_used", 3478) msgResponse.set_int("real_free", 2588) msgResponse.set_int("real_total", 3790) msgResponse.set_int("swap_free", 3036) msgResponse.set_int("swap_total", 3072) msgResponse.set_int("system", 4) msgResponse.set_int("user", 2) msgResponse.set_int("wait", 0) self.write(self.agent_packet, self.sock, msgResponse)
def execute(self): msgResponse = Message(self.r_msg.get_name()) msgResponse.set_int("return_code", 1) self.write(self.agent_packet, self.sock, msgResponse)
def fault_get_current(self): msg = Message("FAULT_GET_CURRENT") msg.set_str('field_name', 'config_id') msg.set_array('field_value', []) return msg
import copy import struct from insoft.openmanager.message.message import Message from insoft.openmanager.message.packet import Packet from insoft.openmanager.message.packet_reader import PacketReader from insoft.openmanager.message.packet_writer import PacketWriter msg = Message("MESSAGE_TEST") msg.set_int("integer", 1) msg.set_float("float", 2.0) msg.set_long("long", 3) msg.set_str("str", "message_test") msg.set_bytes("byte", bytes("message", "utf-8")) msg.set_msg("msg", Message("NEW_MESSAGE")) msg.set_array("array", ["A", "B", "C"]) print(msg)
import copy import socket import struct import time from insoft.openmanager.message.message import Message from insoft.openmanager.message.packet import Packet from insoft.openmanager.message.packet_reader import PacketReader from insoft.openmanager.message.packet_writer import PacketWriter from insoft.openmanager.message.client_packet_dof import DofClientPacket msg = Message("LOGIN") msg.set_str('user_id', 'root') msg.set_str('user_pw', 'changeit') msg.set_int('client_type', 6) print(msg) addr = ('192.168.9.62', 9100) s = socket.socket() s.connect(addr) packet_writer = PacketWriter() b_msg = packet_writer.parse_to_bytes(msg) client_packet = DofClientPacket() client_packet.send(s, b_msg) print("send message...") time.sleep(3)
def config_get_all(self): msg = Message("CONFIG_GET") msg.set_str('field_name', 'user_configs') msg.set_array('field_value', ['0']) return msg