Exemplo n.º 1
0
 def test_get_device(self):
     with requests_mock.mock() as m:
         m.get('https://test.com/api/sysinfo', text=self._load_fixture('fixtures/sysinfo.json'))
         m.get('https://test.com/api/device', text=self._load_fixture('fixtures/api_device_extended.json'))
         m.get('https://test.com/api/device/12345', text=self._load_fixture('fixtures/api_device_12345.json'))
         c = Client('my', 'test', 'https://test.com')
         device = c.get_device(12345)
         self.assertEquals(device.details['name'], 'AU9/kubernetes-master01')
Exemplo n.º 2
0
 def test_get_devices_details(self):
     with requests_mock.mock() as m:
         m.get('https://test.com/api/sysinfo',
               text=self._load_fixture('fixtures/sysinfo.json'))
         m.get('https://test.com/api/device',
               text=self._load_fixture('fixtures/api_device_extended.json'))
         c = Client('my', 'test', 'https://test.com')
         devices = c.devices(details=True)
         self.assertEquals(len(devices), 11)
Exemplo n.º 3
0
 def test_format_get(self):
     with requests_mock.mock() as m:
         m.get('https://test.com/api/sysinfo',
               text=self._load_fixture('fixtures/sysinfo.json'))
         m.get('https://test.com/api/device',
               text=self._load_fixture('fixtures/api_device.json'))
         c = Client('my', 'test', 'https://test.com')
         # prepended /
         info = c.get('/api/sysinfo').json()
         self.assertEquals(info['em7build'], '45945')
Exemplo n.º 4
0
 def test_get_device(self):
     with requests_mock.mock() as m:
         m.get('https://test.com/api/sysinfo',
               text=self._load_fixture('fixtures/sysinfo.json'))
         m.get('https://test.com/api/device',
               text=self._load_fixture('fixtures/api_device_extended.json'))
         m.get('https://test.com/api/device/12345',
               text=self._load_fixture('fixtures/api_device_12345.json'))
         c = Client('my', 'test', 'https://test.com')
         device = c.get_device(12345)
         self.assertEquals(device.details['name'],
                           'AU9/kubernetes-master01')
Exemplo n.º 5
0
from sciencelogic.client import Client
import matplotlib.pyplot as plt


c = Client('jazz', 'hands!', 'https://au-monitoring.mcp-services.net/')

# API details
print(c.sysinfo)

# Get the first device
devices = c.devices(details=True)

for d in devices:
    print(d.details)

# Custom attribute
target_server_id = '56a20d29-95cc-46b8-b43c-41a96be18ace'

# Match by custom attribute
d1 = [device for device in devices
      if device.details['c-server-id'] == target_server_id][0]

# Get the details of the client
print(d1.details)

# Get a list of available performance counters
counters = d1.performance_counters()

print ("Available counters")
for counter in counters:
    print("%s" % (counter.name()))
Exemplo n.º 6
0
def get_data(device_name,
             app_name,
             property_name,
             credentials,
             duration=None,
             begin_timestamp=None,
             end_timestamp=None,
             verbose=False,
             normalized=None):

    from sciencelogic.client import Client

    if isinstance(begin_timestamp, datetime):
        begin_timestamp = totimestamp(begin_timestamp)

    if isinstance(end_timestamp, datetime):
        end_timestamp = totimestamp(end_timestamp)

    c = Client(*credentials)

    device = None

    if not isinstance(device_name, int):
        devices = c.devices(details=True)

        for dev in devices:
            if dev.description == device_name:
                device = dev
                break

        if not device:
            print("could not find device {}".format(device_name))
            print("available devices: {}".format(devices))
            return None
    else:
        try:
            device = c.get_device(device_name)
        except Exception:
            print("could not find device {}".format(device_name))
            return None

    counter = None
    counter_names = []

    for dev_counter in device.performance_counters():
        cn = dev_counter.name()

        if cn[0] == ' ':
            cn = cn.replace(' ', '')

        counter_names.append(cn)
        if cn == app_name:
            counter = dev_counter
            break

    if not counter:
        print("could not find app for {}".format(app_name))
        print("available apps: {}".format(counter_names))
        return None

    data_map = None

    presentations = counter.get_presentations()
    presentation_names = []

    for presentation in presentations:
        presentation_names.append(presentation.name)

        if verbose:
            print("presentation.name='{}' == property_name='{}'? ".format(
                presentation.name, property_name))

        if str(presentation.name) == str(property_name):
            if verbose:
                print("found matching presentation name!")
            if normalized:
                presentation.data_uri = presentation.data_uri.replace(
                    "data?duration=24h", "normalized_hourly?duration=24h")

            data_map = presentation.get_data(beginstamp=begin_timestamp,
                                             endstamp=end_timestamp,
                                             duration=duration)

            if normalized and 'avg' in data_map:
                data_map = data_map['avg']

            break

    if data_map is None:
        print("could not find presentation '{}'' or no data for that period".
              format(property_name))
        if property_name not in presentation_names:
            print("available presentation names: '{}'".format(
                "', '".join(presentation_names)))
        return None

    if verbose:
        print(data_map.keys())

    data_map_size = 0
    data_map_flatter = {}

    # combine all the index keys:

    for index_key in list(data_map.keys()):
        for timestamp, value in data_map[index_key].items():
            data_map_flatter[timestamp] = value

    data_map = data_map_flatter

    data = np.zeros((len(list(data_map)), 2), np.float32)

    data[:, 0] = np.array(list(data_map)).astype(float)
    data[:, 1] = np.array(list(data_map.values())).astype(float)

    return data
Exemplo n.º 7
0
from sciencelogic.client import Client
import matplotlib.pyplot as plt

c = Client('jazz', 'hands!', 'https://au-monitoring.mcp-services.net/')

# API details
print(c.sysinfo)

# Get the first device
devices = c.devices(details=True)

for d in devices:
    print(d.details)

# Custom attribute
target_server_id = '56a20d29-95cc-46b8-b43c-41a96be18ace'

# Match by custom attribute
d1 = [
    device for device in devices
    if device.details['c-server-id'] == target_server_id
][0]

# Get the details of the client
print(d1.details)

# Get a list of available performance counters
counters = d1.performance_counters()

print("Available counters")
for counter in counters:
Exemplo n.º 8
0
 def test_client_bad_values(self):
     with self.assertRaises(ValueError):
         c = Client('me', 'pass', 'potato!')
Exemplo n.º 9
0
 def test_client_bad_param(self):
     with self.assertRaises(TypeError):
         c = Client('potato!')