def get_controllers(session): output = CustomSensorResult("Pure storage controllers") response = session.get('https://mslnrcorpsan3/api/1.15/array?controllers=true', verify=False) results = json.loads(response.text) for item in results: if item['status'] == 'ready': output.add_channel(name=item['mode'], value=0, value_lookup="prtg.standardlookups.purestorage.hardwarestatus") else: output.add_channel(name=item['mode'], value=10, value_lookup="prtg.standardlookups.purestorage.hardwarestatus") print(output.json_result)
def get_hardware(session): output = CustomSensorResult("Pure storage hardware") response = session.get('https://mslnrcorpsan3/api/1.15/hardware', verify=False) results = json.loads(response.text) for item in results: if item['status'] == 'ok' and ('FAN' in item['name'] or 'PWR' in item['name'] or 'FC' in item['name']): output.add_channel(name=item['name'], value=0, value_lookup="prtg.standardlookups.purestorage.hardwarestatus") elif item['status'] != 'ok' and ('FAN' in item['name'] or 'PWR' in item['name'] or 'FC' in item['name']): output.add_channel(name=item['name'], value=10, value_lookup="prtg.standardlookups.purestorage.hardwarestatus") print(output.json_result)
def get_volumes_queue(session): response = session.get('https://mslnrcorpsan3/api/1.15/volume?space=true', verify=False) results = json.loads(response.text) # create sensor result output = CustomSensorResult("Volumes queue depth") for item in results: query = 'https://mslnrcorpsan3/api/1.15/volume' + '/' + item['name'] + '?action=monitor' new_response = session.get(query, verify=False) new_results = json.loads(new_response.text) output.add_channel(channel_name=item['name'].split('-', 1)[1], value=new_results[0]['queue_depth']) print(output.json_result)
def get_volumes_usage(session): response = session.get('https://mslnrcorpsan3/api/1.15/volume?space=true', verify=False) results = json.loads(response.text) # create sensor result output = CustomSensorResult("Array real usage per volume") count = 1 for item in results: channel_name = item['name'] if len(channel_name) > 32: channel_name = channel_name[0:31] output.add_channel(name=channel_name, unit="Bytes", value=item['total']) if count == 50: break count = count + 1 print(output.json_result)
def run(self): self.validateCliParams() mobileScore = self.getScore(self.getApiUrl('mobile')) desktopScore = self.getScore(self.getApiUrl('desktop')) sensor = CustomSensorResult(0) sensor.add_channel(name="Mobile Score", unit="Percent", value=mobileScore) sensor.add_channel(name="Desktop Score", unit="Percent", value=desktopScore) # Send results print(sensor.json_result)
def get_manual_snapshots(session): response = session.get('https://mslnrcorpsan3/api/1.15/volume?snap=true&space=true', verify=False) results = json.loads(response.text) # create sensor result output = CustomSensorResult("List of manually created snapshots") output.add_channel(name="placeholder", unit="Bytes", value=0) count = 1 for item in results: channel_name = item['name'] if len(channel_name) > 32: channel_name = channel_name[0:31] if ( "Standard-Snaps" not in item['name'] ): output.add_channel(name=channel_name, unit="Bytes", value=item['snapshots'], is_limit_mode=True, limit_max_warning=100000000000, limit_warning_msg="Snapshot size too large") if count == 49: break count = count + 1 print(output.json_result)
def get_volumes_bytes_r(session): response = session.get('https://mslnrcorpsan3/api/1.15/volume?space=true', verify=False) results = json.loads(response.text) # create sensor result output = CustomSensorResult("Volumes bytes Read performance") count = 1 for item in results: query = 'https://mslnrcorpsan3/api/1.15/volume' + '/' + item['name'] + '?action=monitor' new_response = session.get(query, verify=False) new_results = json.loads(new_response.text) channel_name = item['name'] if len(channel_name) > 30: channel_name = channel_name[0:29] output.add_channel(name=channel_name + ' R', unit="BytesBandwidth", value=new_results[0]['input_per_sec']) if count == 50: break count = count + 1 print(output.json_result)
def get_capacity(session): response = session.get('https://mslnrcorpsan3/api/1.15/array?space=true', verify=False) results = json.loads(response.text) # create sensor result output = CustomSensorResult("PURE array capacity") for item in results: output.add_channel(name="Capacity", unit="Bytes", value=item['capacity']) output.add_channel(name="Snapshot", unit="Bytes", value=item['snapshots']) output.add_channel(name="Used space", unit="Bytes", value=item['total']) output.add_primary_channel(name="Used %", unit=ValueUnit.PERCENT, value= (item['total'] * 100 / item['capacity']), is_limit_mode=True, limit_max_warning=SIZE_WARNING_THRESHOLD, limit_warning_msg="High array disk space usage", limit_max_error=SIZE_ERROR_THRESHOLD, limit_error_msg="Very high array disk space usage") output.add_channel(name="Data reduction", is_float=True, value=item['data_reduction']) print(output.json_result)
def report_and_exit(message, channels): result = CustomSensorResult(message) # The final step reports elapsed time of the full login/logout sequence # Make it the primary channel # The value is set to 0 when an error was encounterd. Setting the # limit_min_error = 1 will trigger the error state for the channel in PRTG. channels.reverse() for ch in channels: result.add_channel(name=ch['name'], unit='ms', value=ch.get('value', 0), is_float=False, is_limit_mode=True, limit_min_error=1, limit_max_error=5000, limit_min_warning=0, limit_max_warning=3000, limit_error_msg=ch.get('error', 'Timeout')) print(result.json_result) exit()
def get_performance(session): response = session.get('https://mslnrcorpsan3/api/1.15/array?action=monitor', verify=False) results = json.loads(response.text) # create sensor result output = CustomSensorResult("PURE array performance") for item in results: output.add_channel(name="Write bytes per second", unit="Bytes", value=item['output_per_sec']) output.add_channel(name="Read bytes per second", unit="Bytes", value=item['input_per_sec']) output.add_primary_channel(name="Queue depth", value=item['queue_depth'], is_limit_mode=True, limit_max_warning=60, limit_warning_msg="Large queue depth") output.add_channel(name="Write IOPS per second", unit="IOPS", value=item['writes_per_sec']) output.add_channel(name="Read IOPS per second", unit="IOPS", value=item['reads_per_sec']) output.add_channel(name="Write latency", unit="usec", value=item['usec_per_write_op']) output.add_channel(name="Read latency", unit="usec", value=item['usec_per_read_op']) print(output.json_result)
def get_drives(session): response = session.get('https://mslnrcorpsan3/api/1.15/drive', verify=False) results = json.loads(response.text) output = CustomSensorResult("Disks status") for item in results: if item['status'] == 'healthy': output.add_channel(name=item['name'], value=0, value_lookup="prtg.standardlookups.purestorage.drivestatus") elif item['status'] == 'empty': output.add_channel(name=item['name'], value=1, value_lookup="prtg.standardlookups.purestorage.drivestatus") elif item['status'] == 'updating': output.add_channel(name=item['name'], value=2, value_lookup="prtg.standardlookups.purestorage.drivestatus") elif item['status'] == 'unused': output.add_channel(name=item['name'], value=3, value_lookup="prtg.standardlookups.purestorage.drivestatus") elif item['status'] == 'evacuating': output.add_channel(name=item['name'], value=4, value_lookup="prtg.standardlookups.purestorage.drivestatus") elif item['status'] == 'identifying': output.add_channel(name=item['name'], value=5, value_lookup="prtg.standardlookups.purestorage.drivestatus") elif item['status'] == 'unhealthy': output.add_channel(name=item['name'], value=6, value_lookup="prtg.standardlookups.purestorage.drivestatus") elif item['status'] == 'recovering': output.add_channel(name=item['name'], value=7, value_lookup="prtg.standardlookups.purestorage.drivestatus") elif item['status'] == 'unrecognized': output.add_channel(name=item['name'], value=8, value_lookup="prtg.standardlookups.purestorage.drivestatus") elif item['status'] == 'failed': output.add_channel(name=item['name'], value=9, value_lookup="prtg.standardlookups.purestorage.drivestatus") print(output.json_result)
return int(return_message['emeter']['get_realtime']['power_mw']) / 1000 if __name__ == "__main__": try: data = json.loads(sys.argv[1]) # Setup the handler class for the smartplug connection sp_handler = SmartPlugHandler(data["host"], 9999) # Sends request to get the wattage consumption of the plug wattage_consumption = sp_handler.get_wattage_consumption() # Sends request to get the relay state of the plug relay_state = sp_handler.get_relay_state() csr = CustomSensorResult(text="This sensor runs on %s" % data["host"]) csr.add_primary_channel(name="Power Usage", value=wattage_consumption, unit="Watt", is_float=True) csr.add_channel(name="Power State", value=relay_state, unit=ValueUnit.PERCENT) print(csr.json_result) except Exception as e: csr = CustomSensorResult(text="Python Script execution error") csr.error = "Python Script execution error: %s" % str(e) print(csr.json_result)
from prtg.sensor.units import ValueUnit if __name__ == "__main__": try: data = json.loads(sys.argv[1]) csr = CustomSensorResult(text="This sensor runs on %s" % data["host"]) csr.add_primary_channel(name="Percentage", value=87, unit=ValueUnit.PERCENT, is_float=False, is_limit_mode=True, limit_min_error=10, limit_max_error=90, limit_error_msg="Percentage too high") csr.add_channel(name="Response Time", value=4711, unit=ValueUnit.TIMERESPONSE) print(csr.json_result) except Exception as e: csr = CustomSensorResult(text="Python Script execution error") csr.error = "Python Script execution error: %s" % str(e) print(csr.json_result) # ------------------------------------------------------------ # # Citation(s) # # dev.to | "Python to .exe: How to convert .py to .exe? Step by step guide. - DEV" | https://dev.to/eshleron/how-to-convert-py-to-exe-step-by-step-guide-3cfi # # psutil.readthedocs.io | "psutil documentation — psutil 5.7.1 documentation" | https://psutil.readthedocs.io/en/latest/ #
status = 1 elif output['status'] == 'red': status = 2 #turn timed out into a number so that it can be viewed in prtg if output['timed_out'] == False: timedOut = 0 else: timedOut = 1 #create a prtg sensor and add the channel data. Each key/value in the json response from ES gets channelised sensor = CustomSensorResult(output['status']) sensor.add_channel(name="Status", unit="Count", value=status, is_limit_mode=True, limit_max_error=1.5, limit_max_warning=0.5) sensor.add_channel(name="Number Of Data Nodes", unit="Count", value=output['number_of_data_nodes']) sensor.add_channel(name="Number of Nodes", unit="Count", value=output['number_of_nodes']) sensor.add_channel(name="Percent of Shards Active", unit="Percent", value=output['active_shards_percent_as_number']) sensor.add_channel(name="Delayed Unassigned Shards", unit="Count", value=output['delayed_unassigned_shards']) sensor.add_channel(name="In Flight Fetches",
for channel in range(num_ps_found): power_supply_item = ps_status_list.pop() p_name = power_supply_item[0] if power_supply_item[1] == "True": insert_status = 1 else: insert_status = 0 if power_supply_item[2] == "True": alarm_status = 1 else: alarm_status = 0 csr.add_channel( name="{} insert status".format(p_name), value=insert_status, unit=ValueUnit.CUSTOM, is_float=False, is_limit_mode=True, limit_min_error=1, limit_error_msg="power module {} is not in place".format( p_name)) csr.add_channel( name="{} alarm status".format(p_name), value=alarm_status, unit=ValueUnit.CUSTOM, is_float=False, is_limit_mode=True, limit_max_error=0, limit_error_msg="alarm on module {}".format(p_name)) logging.debug(csr.json_result) except Exception as e:
container, viewType, recursive) children = containerView.view vms = [] # Loop through all the VMs for child in children: if child.summary.config.name.startswith(vmHeaderName + "-("): vms.append(child) if isPrtg: #check if there are any vms with this header name to avoid firs time error if len(vms) != 0: for vm in vms: csr.add_channel(name=vm.summary.config.name, value=round( vm.summary.quickStats.overallCpuUsage / 1000, 3), unit="GHz", is_float=True) #is_limit_mode=True, #limit_min_error=10, #limit_max_error=80, #limit_error_msg="Percentage too high") else: csr.add_channel(name="No Vm's", value=0, unit="GHz", is_float=False) else: print("Host: " + vm.summary.guest.guestFullName + "CPU: " + round(vm.summary.quickStats.overallCpuUsage / 1000, 3) +
"host"] # Automatically read from it's device IP comfoconnect_pin = extract_pin( data ) # Pin needs to be defined in sensor settings: "Additonal parameters: <pin>", default is 0 # Gets all the data run_comfoconnect_handler(comfoconnect_ip, comfoconnect_pin) # Status Message is depending on the values of the operation and ventilation stage sensors csr = CustomSensorResult( text= f"{set_status_message(sensor_data[56], sensor_data[SENSOR_FAN_SPEED_MODE])}" ) csr.add_channel(name="Betriebsmodus", value=sensor_data[56], unit="Modus") csr.add_channel(name="Lüftungsstufe", value=sensor_data[SENSOR_FAN_SPEED_MODE], unit="Stufe", is_limit_mode=True, limit_min_warning=-0.1, limit_max_warning=3.1) csr.add_channel(name="Volumen Fortluftventilator", value=sensor_data[SENSOR_FAN_EXHAUST_FLOW], unit="m³/h", is_limit_mode=True, limit_min_warning=40)
historicStr = str(historicCsv.content) # convert string csv raw data of historic data to matrix historic_mat = csv_historic_data_str_to_mat(historicStr) # create esxi list esxi_dict = create_esxi_list(historic_mat) # iterate over the historic data and count alive time and how much above limit for rows in range(1, len(historic_mat) - 2): for cols in range(3, len(historic_mat[0]) - 2, 2): if historic_mat[rows][cols] != "": esxi_dict[historic_mat[0][cols - 1]][0] += 1 if float(historic_mat[rows][cols]) >= limit: esxi_dict[historic_mat[0][cols - 1]][1] += 1 # create channel for esxi for esxi in esxi_dict: csr.add_channel(name=esxi, value=round((esxi_dict[esxi][1] / esxi_dict[esxi][0]) * 100, 2), unit="%", is_float=True) print(csr.json_result) except Exception as e: csr = CustomSensorResult(text="Python Script execution error") csr.error = "Python Script execution error: %s" % str(e) print(csr.json_result)
import json import sys from prtg.sensor.result import CustomSensorResult from prtg.sensor.units import ValueUnit g = Gigya() g.set_api_key( '3_e8d4g4SE_Fo8ahyHwwP7ohLGZ79HKNN2T8NjQqoNnk6Epj6ilyYwKdHUyCw3wuxz') g.login('email', 'password') g.account_info() k = Kamereon(gigya=g) k.set_api_key('Ae9FDWugRxZQAGm3Sxgk7uJn6Q4CGEA2') v = Vehicle('VIN', k) data = v.battery_status() data_hvac = v.hvac_status() sensor = CustomSensorResult() sensor.add_channel(name='Battery Percentage', unit='Percent', value=data['batteryLevel']) sensor.add_channel(name='Range', unit='KM', value=data['batteryAutonomy']) sensor.add_channel(name='External Temperature', unit='Temperature', value=data_hvac['externalTemperature']) sensor.add_channel(name='Plugged In', value=data['plugStatus']) sensor.add_channel(name='Charging Status', value=data['chargingStatus']) print(sensor.json_result)
container, viewType, recursive) children = containerView.view vms = [] # Loop through all the VMs for child in children: if child.summary.config.name.startswith(vmHeaderName + "-("): vms.append(child) if isPrtg: #check if there are any vms with this header name to avoid firs time error if len(vms) != 0: for vm in vms: csr.add_channel(name="CPU-" + vm.summary.config.name, value=round( vm.summary.quickStats.overallCpuUsage / 1000, 3), unit="GHz", is_float=True) #is_limit_mode=True, #limit_min_error=10, #limit_max_error=80, #limit_error_msg="Percentage too high") csr.add_channel( name="Memory-" + vm.summary.config.name + " , " + vm.summary.guest.hostName, value=vm.summary.quickStats.guestMemoryUsage, unit="MB", is_float=False) #is_limit_mode=True, #limit_min_error=10,
container, viewType, recursive) children = containerView.view vms = [] # Loop through all the VMs for child in children: if child.summary.config.name.startswith(vmHeaderName + "-("): vms.append(child) if isPrtg: #check if there are any vms with this header name to avoid firs time error if len(vms) != 0: for vm in vms: csr.add_channel( name=vm.summary.config.name, value=vm.summary.quickStats.guestMemoryUsage, unit="MB", is_float=False) #is_limit_mode=True, #limit_min_error=10, #limit_max_error=80, #limit_error_msg="Percentage too high") else: csr.add_channel(name="No Vm's", value=0, unit="MB", is_float=False) else: print("name: " + vm.summary.config.name + "\nmemory usage: " + str(vm.summary.quickStats.guestMemoryUsage))