Пример #1
0
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)
Пример #2
0
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)
Пример #3
0
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)
Пример #4
0
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()
Пример #5
0
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)     
Пример #6
0
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 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)
Пример #8
0
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)
Пример #9
0

if __name__ == "__main__":
    try:
        data = json.loads(sys.argv[1])

        #handle parameters
        params = data["params"].split()
        host_ip = params[0]
        user = params[1]
        password = params[2]
        limit = float(params[3])
        days_range = int(params[4])
        cluster_id = params[5]

        csr = CustomSensorResult(text="percent time above " + str(limit) + "% for the last %s days " % params[4])

        # get response from server
        device_response = requests.get("http://10.250.0.187/api/table.json?username=prtgadmin&password=prtgadmin")

        # get string of current date
        now = datetime.datetime.now()
        e_time = now.strftime("%Y-%m-%d-%H-%M-%S")
        s_time = now - datetime.timedelta(days=days_range)
        s_time = s_time.strftime("%Y-%m-%d-%H-%M-%S")
        print("time before x days: " + str(s_time))

        # check successful connection to prtg server
        if str(device_response) != "<Response [200]>":
            raise SystemExit("Unable to connect to prtg server.")
Пример #10
0
json_default = {}

url_web_service = 'http://localhost:7778/caducidadEmpresaDiasAll'

try:
    url_contenido = urllib.request.urlopen(url_web_service)
    parametros = json.loads(url_contenido.read().decode("utf-8"))
except Exception as inst:
    parametros = json_default

# lTiempoCaducidad = parametros["valor"]["lCaducidad"]
# lNombreEmpresa = parametros["valor"]["nombre_empresa"]

# print("Nombre Empresa: ", lNombreEmpresa)
# print("Estos son los dias para que caduque el contrato: ", lTiempoCaducidad)

lParametros = parametros["valor"]

if __name__ == "__main__":
    # interpreta el primer parámetro de línea de comando como objeto json
    data = json.loads(sys.argv[1])
    # crear resultado del sensor
    result = CustomSensorResult("OK")
    # Añadir canal
    for parametros in lParametros:
        result.add_primary_channel(name=parametros["nombre_empresa"],
                                   unit="Count",
                                   value=parametros["lCaducidad"],
                                   is_float=False)
    print(result.json_result)
Пример #11
0
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)
Пример #12
0
        return_message = json.loads(self._send_command_and_get_reply('energy'))
        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)
Пример #13
0
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)
Пример #14
0
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)
Пример #15
0
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)
Пример #16
0
if __name__ == "__main__":
    try:
        data = json.loads(sys.argv[1])

        comfoconnect_ip = data[
            "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],
Пример #17
0
        fw = Firewall(host, api_username=username, api_password=passwd)
        env_info = fw.op("show system environmentals", xml=True)
        env_decode = env_info.decode("utf-8")
        tree = ET.fromstring(str(env_decode))
        ps_items = tree.xpath(".//power-supply/Slot1/entry/description")
        ps_status_list = []
        for ps_item in ps_items:
            ps_status = []
            ps_des = ''.join(ps_item.itertext())
            ps_status.append(ps_des)
            for sb_item in ps_item.itersiblings(preceding=True):
                ps_status.append(sb_item.text)
            ps_status_list.append(ps_status)
        num_ps_found = len(ps_status_list)

        csr = CustomSensorResult(
            text="This sensor runs on {}".format(data["host"]))
        csr.add_primary_channel(
            name="Node need {} Power supplies".format(num_ps_found),
            value=num_ps_found,
            unit=ValueUnit.CUSTOM,
            is_limit_mode=True,
            limit_min_error=num_ps_found,
            show_table=False,
            limit_error_msg="power module is missing")

        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:
 def sendError(self, message):
     result = CustomSensorResult()
     result.add_error('Error occurred: ' + message)
     print(result.json_result)
     exit(1)
Пример #19
0
# -*- coding: utf-8 -*-

# pip install --upgrade pip
# pip install --upgrade psutil

import json
import psutil
import sys

from prtg.sensor.result import CustomSensorResult
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)
Пример #20
0
    #Turn status colour into a number so that it can be viewed in prtg
    if output['status'] == 'green':
        status = 0
    elif output['status'] == 'yellow':
        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",
Пример #21
0
                        action='store',
                        help='header vm to monitor')
    parser.add_argument('-p',
                        '--password',
                        required=False,
                        action='store',
                        help='Password to use when connecting to host')
    args = parser.parse_args()
    return args


if __name__ == "__main__":
    try:
        data = json.loads(sys.argv[1])
        if isPrtg:
            csr = CustomSensorResult(text="This sensor runs on %s" %
                                     data["host"])

            #handle parameters
            params = data["params"].split()
            host = params[0]
            user = params[1]
            password = params[2]
        else:
            GetArgs()

        vmHeaderName = ' '.join(params[3:])

        # connect to vcenter
        try:
            if isPrtg:
                si = SmartConnectNoSSL(host=host, user=user, pwd=password)
Пример #22
0
                        action='store',
                        help='header vm to monitor')
    parser.add_argument('-p',
                        '--password',
                        required=False,
                        action='store',
                        help='Password to use when connecting to host')
    args = parser.parse_args()
    return args


if __name__ == "__main__":
    try:
        data = json.loads(sys.argv[1])
        if isPrtg:
            csr = CustomSensorResult(text="This sensor runs on %s" %
                                     data["host"])

            #handle parameters
            params = data["params"].split()
            host = params[0]
            user = params[1]
            password = params[2]
        else:
            GetArgs()

        vmHeaderName = ' '.join(params[3:])

        # connect to vcenter
        try:
            if isPrtg:
                si = SmartConnectNoSSL(host=host, user=user, pwd=password)