Пример #1
0
 def reg_msg_handler(self, msg_info, reply=None):
     try:
         logger.debug("Registration msg handler called.")
         if reply:
             for single_response in reply.payloads:
                 if single_response.return_value == 0:
                     logger.info("\t\tRegistration ACK received.")
                     # change status to YES in config file
                     config = ConfigObj(config_file_name)
                     config["Registered"] = "YES"
                     config["UTC Time"] = single_response.output
                     bashit("date -s@"+str(single_response.output))
                     config.write()
                     start_communication_with_nc_event.set()
                     logger.info("Start_communication_with_nc_event is set.")
                 else:
                     logger.critical("ERROR: Unknown ACK received: Discarding..")
             return   
         # handle failure
         logger.critical("Registration timeout.............")
         msg_info[2] = self.calculate_expiration_time(registration_type, None)
         self.add_to_sent_msgs_bfr(msg_info)
         self.send_msg_to_nc(msg_info[3])
         logger.critical("Registration msg resent.............")
     except Exception as inst:
         logger.critical("ERROR: Exception in reg_msg_handler: " + str(inst))
Пример #2
0
def get_node_info(config_file_name):
        
    config_object = ConfigObj(config_file_name)
    config = config_object["Systems Info"]
    
    
    list_of_keywords = ["hostname", "noOfProcessors", "cpuModelName", "cpuVendorID", "extensions", "hardware", "interfaces",
                        "memTotal", "osName", "osVersion", "osID", "osPrettyName", "osVersionID", "osKernelRelease", "machineName", "kernelVersion", "diskStorage"]
    
    list_of_cmds = [
                    "hostname", 
                    "cat /proc/cpuinfo  | grep -i  processor | wc -l", 
                    "cat /proc/cpuinfo  | grep -i  model\ name | uniq | tr -s ' ' | cut -d ':' -f 2",
                    "cat /proc/cpuinfo | grep -i  vendor_id | uniq | cut -d ':' -f 2",
                    ["cat /proc/cpuinfo | grep -i  flags | tr ' ' '\n' | sort | uniq | grep -i  -v flag | tr '\n' ' '", "cat /proc/cpuinfo | grep -i  features | tr ' ' '\n' | sort | uniq | grep -i  -v features | tr '\n' ' '"],
                    "cat /proc/cpuinfo | grep -i hardware | cut -d ':' -f 2",
                    ["ls /sys/class/net/", "cat /sys/class/net/"],
                    'cat /proc/meminfo | tr -s " "  | grep -i  MemTotal | cut -d ":" -f 2',
                    'cat /etc/os-release | grep -i NAME | grep -vi "pretty_name" | cut -d "=" -f 2 ',
                    'cat /etc/os-release | grep -i VERSION | grep -vi "version_id" |cut -d "=" -f 2',
                    'cat /etc/os-release | grep -i ID=ubuntu | cut -d "=" -f 2',
                    'cat /etc/os-release | grep -i PRETTY_NAME | cut -d "=" -f 2',
                    'cat /etc/os-release | grep -i VERSION_ID | cut -d "=" -f 2',
                    'uname -r',
                    'uname -m',
                    'cat /proc/version',
                    "df -h  | tr -s ' ' | cut -d ' ' -f 1,2,5,6 | tr '\n' ';' | sed 's/;/\ ;\ /g'"
                ]
                
    for key, cmd in zip(list_of_keywords, list_of_cmds):
        try:
            if not isinstance(cmd, list):
                config[key] = bashit(cmd)
            else:
                if key == "interfaces":
                    interfaces = bashit(cmd[0])
                    interfaces=interfaces.split('\n')
                    config[key] = interfaces
                    if interfaces:
                        interface_details = ''
                        for i in interfaces:
                            if i <> 'lo':
                                interface_details += str(i) + ',' + bashit(cmd[1]+str(i)+"/address") + '\n'
                        interface_details = interface_details.split('\n')
                        config[key] = interface_details
                elif key == 'extensions':
                    config[key] = bashit(cmd[0])
                    if not config[key]:
                        config[key] = bashit(cmd[1])
            if not config[key]:
                    del config[key]  
        except Exception as inst:
            logger.critical("Exception in get_system_info: " + str(inst) + "while executing command " + str(cmd) +"\n\n")
            return 1 
    config_object.write()        
    return 0
	},
	'HMC5883' : {
		'name' : 'HMC5883.Honeywell.2013',
		'data': 'Magnetic_Field;' + str("{0:.2f}".format(random.uniform(-8,8))) + ';gauss;X,Magnetic_Field;' + str("{0:.2f}".format(random.uniform(-8,8))) + ';gauss;Y,Magnetic_Field;' + str("{0:.2f}".format(random.uniform(-8,8))) + ';gauss;Z'
	}
}

def getData(sensorName):
	return sensors[sensorName]['name'] + ',' + current_time + ',' + sensors[sensorName]['data'] + '\n'

# -----------------------------------------------
# Overwrite the file containing the current data.
try:
    currentFilePtr = open('./current/current', 'w+')
except:
    bashit('mkdir current')
    currentFilePtr = open('./current/current', 'w+')

for sensor in sensors.keys():
	currentFilePtr.write(getData(sensor))

currentFilePtr.close()

# ------------------------------------------------
# Append the latest data to the files containing historical data for each sensor.
try:
    historical_prt = open('./historical/BMP180', 'a+')
except:
    bashit('mkdir historical')

for sensor in sensors.keys():