Healthbot Python客户端

hbez的Python项目详细描述


Documentation StatusUnitTest Status

HealthBot Python客户端

这个repo包含一个Python包来控制HealthBot

这个包的目的是提供一个Python库 自动配置HealthBot服务器。在

示例

导入HbEZ库

fromjnpr.healthbotimportHealthBotClientfrompprintimportpprint

打开连接

^{pr2}$

使用Pythonwith上下文管理器

  • 使用访问令牌处理登录和注销
withHealthBotClient('xx.xx.xx.xxx','xxxxx','xxxxx',port=nnnn)ashb:pprint(hb.device.get_ids())

用例:设备

pprint(hb.device.get_ids())
['edge', 'srx', 'qfx', 'mx-edge', 'core', 'node', 'demo']

获取任何给定函数的帮助

help(hb.device.get_ids)
Help on method get_ids in module jnpr.healthbot.modules.devices:

get_ids() method of jnpr.healthbot.modules.devices.Device instance
    Return Device IDs for all the devices in HealthBot system

    :return: list of device IDs

    Example:
    ::

        from jnpr.healthbot import HealthBotClient
        hb = HealthBotClient('xx.xxx.x.xx', 'xxxx', 'xxxx', port=nnnn)
        print(hb.device.get_ids())

获取与给定设备id相关的配置

# Get config related to given device-idobj=hb.device.get('demo')
obj.host
'xx.xxx.x.xx'
pprint(obj)
{'authentication': {'password': {'password': 'xxx',
                                 'username': 'xxxx'}},
 'description': None,
 'device_id': 'demo',
 'host': 'xx.xxx.x.xx',
 'i_agent': None,
 'open_config': None,
 'snmp': None,
 'system_id': 'test:HbEZ',
 'variable': None,
 'vendor': None}

获取给定设备id

# Get device facts of a given device idpprint(hb.device.get_facts('demo'))
{'device-id': 'demo',
 'facts': {'fpc': [],
           'hostname': 'R1_re0',
           'junos-info': [{'last-reboot-reason': 'Router rebooted after a '
                                                 'normal shutdown.',
                           'mastership-state': 'master',
                           'model': 'RE-VMX',
                           'name': 're0',
                           'status': 'OK',
                           'up-time': '98 days, 3 minutes, 49 seconds',
                           'version-info': {'build': '0',
                                            'major': [19, 3],
                                            'minor': ['20190421_dev_common'],
                                            'type': 'I'}}],
           'platform': 'MX960',
           'platform-info': [{'name': 're0', 'platform': 'MX960'}],
           'product': 'MX',
           'release': '19.3-20190421_dev_common.0.84473',
           'serial-number': 'xxxx'}}

添加新设备

fromjnpr.healthbotimportDeviceSchemads=DeviceSchema(device_id='demo',host='xx.xxx.x.xx',authentication={"password":{"password":"xxxx","username":"xxxx"}})print(hb.device.add(schema=ds))
True
help(DeviceSchema)
Help on class DeviceSchema in module jnpr.healthbot.swagger.models.device_schema:

class DeviceSchema(builtins.object)
 |  NOTE: This class is auto generated by the swagger code generator program.
 |  
 |  Do not edit the class manually.
 |  
 |  Methods defined here:
 |  
 |  __eq__(self, other)
 |      Returns true if both objects are equal
 |  
 |  __init__(self, authentication=None, description=None, device_id=None, host=None, i_agent=None, open_config=None, snmp=None, system_id=None, variable=None, vendor=None)
 |      DeviceSchema - a model defined in Swagger
 |  
 |  __ne__(self, other)
 |      Returns true if both objects are not equal
 |  
 |  __repr__(self)
 |      For `print` and `pprint`
 |  
 |  to_dict(self)
 |      Returns the model properties as a dict
 |  
 |  to_str(self)
 |      Returns the string representation of the model
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)
 |  
 |  authentication
 |      Gets the authentication of this DeviceSchema.  # noqa: E501
 |      
 |      
 |      :return: The authentication of this DeviceSchema.  # noqa: E501
 |      :rtype: DeviceSchemaAuthentication
 |  
 |  description
 |      Gets the description of this DeviceSchema.  # noqa: E501
 |      
 |      Description about the device  # noqa: E501
 |      
 |      :return: The description of this DeviceSchema.  # noqa: E501
 |      :rtype: str
 |  
 |  device_id
 |      Gets the device_id of this DeviceSchema.  # noqa: E501
 |      
 |      Identifier for the device. Should be of pattern [a-zA-Z][a-zA-Z0-9_-]*  # noqa: E501
 |      
 |      :return: The device_id of this DeviceSchema.  # noqa: E501
 |      :rtype: str
 |  
 |  host
 |      Gets the host of this DeviceSchema.  # noqa: E501
 |      
 |      Name or IP the device  # noqa: E501
 |      
 |      :return: The host of this DeviceSchema.  # noqa: E501
 |      :rtype: str
 |  
 |  i_agent
 |      Gets the i_agent of this DeviceSchema.  # noqa: E501
 |      
 |      
 |      :return: The i_agent of this DeviceSchema.  # noqa: E501
 |      :rtype: DeviceSchemaIAgent
 |  
 |  open_config
 |      Gets the open_config of this DeviceSchema.  # noqa: E501
 |      
 |      
 |      :return: The open_config of this DeviceSchema.  # noqa: E501
 |      :rtype: DeviceSchemaOpenconfig
 |  
 |  snmp
 |      Gets the snmp of this DeviceSchema.  # noqa: E501
 |      
 |      
 |      :return: The snmp of this DeviceSchema.  # noqa: E501
 |      :rtype: DeviceSchemaSnmp
 |  
 |  system_id
 |      Gets the system_id of this DeviceSchema.  # noqa: E501
 |      
 |      ID which is sent in the JTI UDP messages  # noqa: E501
 |      
 |      :return: The system_id of this DeviceSchema.  # noqa: E501
 |      :rtype: str
 |  
 |  variable
 |      Gets the variable of this DeviceSchema.  # noqa: E501
 |      
 |      Playbook variable configuration  # noqa: E501
 |      
 |      :return: The variable of this DeviceSchema.  # noqa: E501
 |      :rtype: list[DeviceSchemaVariable]
 |  
 |  vendor
 |      Gets the vendor of this DeviceSchema.  # noqa: E501
 |      
 |      
 |      :return: The vendor of this DeviceSchema.  # noqa: E501
 |      :rtype: DeviceSchemaVendor
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |  
 |  __hash__ = None
 |  
 |  attribute_map = {'authentication': 'authentication', 'description': 'd...
 |  
 |  swagger_types = {'authentication': 'DeviceSchemaAuthentication', 'desc...
dev=hb.device.get('demo')pprint(dev)
{'authentication': {'password': {'password': 'xxxx',
                                 'username': 'xxxx'}},
 'description': None,
 'device_id': 'demo',
 'host': 'xx.xxx.x.xx',
 'i_agent': None,
 'open_config': None,
 'snmp': None,
 'system_id': None,
 'variable': None,
 'vendor': None}

默认情况下,get()返回未提交的数据(来自候选数据库)

^{pr21}$
{
  "detail": "Device id demo not found",
  "status": 404
}




---------------------------------------------------------------------------

HTTPError                                 Traceback (most recent call last)

<ipython-input-25-13c8b67cdb5c> in <module>
----> 1 pprint(hb.device.get('demo', uncommitted=False))


~/Coding/git.juniper.net.iceberg/healthbot-py-client/lib/jnpr/healthbot/modules/devices.py in get(self, device_id, uncommitted)
    217             if response.status_code != 200:
    218                 logger.error(response.text)
--> 219             response.raise_for_status()
    220             return self.hbot._create_schema(response, DeviceSchema)
    221         else:


/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests/models.py in raise_for_status(self)
    933 
    934         if http_error_msg:
--> 935             raise HTTPError(http_error_msg, response=self)
    936 
    937     def close(self):


HTTPError: 404 Client Error: NOT FOUND for url: https://10.209.7.33:8080/api/v1/device/demo

为什么我们选择使用模式。我们可以轻松访问和编辑任何属性。

# Existing system_idprint(dev.system_id)
None
# Editing system_iddev.system_id="Demo:HbEZ"
print(hb.device.update(dev))
True

HealthBot API提供提交和回滚配置

hb.commit()
True
dev=hb.device.get('demo')pprint(dev)
^{pr31}$
print(dev.system_id)
Demo:HbEZ
# To delete a devicehb.device.delete('demo')# if a device is part of device group, to make sure we delete it first from device grouphb.device.delete('demo',force=True)

用例:设备

获取系统中所有设备的详细信息

^{pr35}$
obj
[{'authentication': {'password': {'password': 'xxxx',
                                  'username': 'xxxx'}},
  'description': None,
  'device_id': 'xxxx',
  'host': 'xx.xxx.x.xx',
  'i_agent': None,
  'open_config': {'port': 32767},
  'snmp': None,
  'system_id': None,
  'variable': [],
  'vendor': {'juniper': {'operating-system': 'junos'}}},
 {'authentication': {'password': {'password': 'xxxx',
                                  'username': 'xxxx'}},
  'description': None,
  'device_id': 'xxx',
  'host': 'xx.xxx.x.xx9',
  'i_agent': {'port': 830},
  'open_config': {'port': 32767},
  'snmp': None,
  'system_id': None,
  'variable': [],
  'vendor': {'juniper': {'operating-system': 'junos'}}},
 {'authentication': {'password': {'password': 'xxxx',
                                  'username': 'xxxx'}},
  'description': None,
  'device_id': 'xxx',
  'host': 'xx.xxx.x.xx',
  'i_agent': {'port': 830},
  'open_config': {'port': 32767},
  'snmp': None,
  'system_id': 'changed description',
  'variable': [],
  'vendor': {'juniper': {'operating-system': 'junos'}}},
 {'authentication': {'password': {'password': 'xxxx',
                                  'username': 'xxxx'}},
  'description': None,
  'device_id': 'demo',
  'host': 'xx.xxx.x.xx',
  'i_agent': None,
  'open_config': None,
  'snmp': None,
  'system_id': 'Demo:HbEZ',
  'variable': None,
  'vendor': None},
 {'authentication': {'password': {'password': 'xxxx',
                                  'username': 'xxxx'}},
  'description': None,
  'device_id': 'vmx_db',
  'host': 'xx.xxx.x.xx',
  'i_agent': {'port': 830},
  'open_config': {'port': 32767},
  'snmp': None,
  'system_id': None,
  'variable': [],
  'vendor': {'juniper': {'operating-system': 'junos'}}},
 {'authentication': {'password': {'password': 'xxxx',
                                  'username': 'xxxx'}},
  'description': None,
  'device_id': 'core_db',
  'host': 'xx.xxx.x.xx',
  'i_agent': {'port': 830},
  'open_config': {'port': 32767},
  'snmp': None,
  'system_id': None,
  'variable': [],
  'vendor': {'juniper': {'operating-system': 'junos'}}},
 {'authentication': {'password': {'password': 'xxxx',
                                  'username': 'xxxx'}},
  'description': None,
  'device_id': 'node1',
  'host': 'node1',
  'i_agent': None,
  'open_config': {'port': 32767},
  'snmp': None,
  'system_id': None,
  'variable': None,
  'vendor': {'juniper': {'operating-system': 'junos'}}}]

获取HB

中所有设备的设备事实
pprint(hb.device.get_facts())
[{'device-id': 'edge', 'facts': {}},
 {'device-id': 'EVO',
  'facts': {'fpc': [{'description': 'FPC-JNP10003-LOGICAL',
                     'model-number': None,
                     'name': 'FPC 1',
                     'part-number': 'BUILTIN',
                     'serial-number': 'BUILTIN',
                     'version': None}],
            'hostname': None,
            'junos-info': [{'last-reboot-reason': 'Unknown',
                            'mastership-state': 'Master',
                            'model': 'Control Board',
                            'name': 're0',
                            'status': 'OK',
                            'up-time': '0 second',
                            'version-info': {'build': None,
                                             'major': [19, 4],
                                             'minor': ['20190731122440-EVO_soumikd'],
                                             'type': 'I'}}],
            'platform': 'PTX10003-160C',
            'platform-info': [{'name': 're0', 'platform': 'PTX10003-160C'}],
            'product': 'PTX',
            'release': '19.4I20190731122440-EVO_soumikd',
            'serial-number': 'xxxx'}},
 {'device-id': 'vmx',
  'facts': {'fpc': [],
            'hostname': 'R1_re0',
            'junos-info': [{'last-reboot-reason': 'Router rebooted after a '
                                                  'normal shutdown.',
                            'mastership-state': 'master',
                            'model': 'RE-VMX',
                            'name': 're0',
                            'status': 'OK',
                            'up-time': '80 days, 1 hour, 20 minutes, 9 seconds',
                            'version-info': {'build': '0',
                                             'major': [19, 3],
                                             'minor': ['20190421_dev_common'],
                                             'type': 'I'}}],
            'platform': 'MX960',
            'platform-info': [{'name': 're0', 'platform': 'MX960'}],
            'product': 'MX',
            'release': '19.3-20190421_dev_common.0.84473',
            'serial-number': 'xxxx'}},
 {'device-id': 'demo',
  'facts': {'fpc': [],
            'hostname': 'R1_re0',
            'junos-info': [{'last-reboot-reason': 'Router rebooted after a '
                                                  'normal shutdown.',
                            'mastership-state': 'master',
                            'model': 'RE-VMX',
                            'name': 're0',
                            'status': 'OK',
                            'up-time': '98 days, 38 minutes, 25 seconds',
                            'version-info': {'build': '0',
                                             'major': [19, 3],
                                             'minor': ['20190421_dev_common'],
                                             'type': 'I'}}],
            'platform': 'MX960',
            'platform-info': [{'name': 're0', 'platform': 'MX960'}],
            'product': 'MX',
            'release': '19.3-20190421_dev_common.0.84473',
            'serial-number': 'xxxx'}},
 {'device-id': 'vmx_db',
  'facts': {'hostname': 'riad001-g',
            'junos-info': [],
            'platform': 'MX480',
            'platform-info': [{'name': 're0', 'platform': 'MX480'}],
            'product': None,
            'release': '19.4I20190809_0730_madhus',
            'serial-number': None}},
 {'device-id': 'core_db',
  'facts': {'fpc': [{'description': 'MPC Type 2 3D',
                     'model-number': 'MX-MPC2-3D',
                     'name': 'FPC 1',
                     'part-number': '750-031089',
                     'serial-number': 'xxxx',
                     'version': 'REV 31'}],
            'hostname': 'choc-mx480-b',
            'junos-info': [{'last-reboot-reason': 'Router rebooted after a '
                                                  'normal shutdown.',
                            'mastership-state': 'master',
                            'model': 'RE-S-2000',
                            'name': 're0',
                            'status': 'OK',
                            'up-time': '5 hours, 27 minutes, 15 seconds',
                            'version-info': {'build': None,
                                             'major': [19, 4],
                                             'minor': ['20190809_0730_madhus'],
                                             'type': 'I'}},
                           {'last-reboot-reason': '0x1:power cycle/failure',
                            'mastership-state': 'backup',
                            'model': 'RE-S-2000',
                            'name': 're1',
                            'status': 'OK',
                            'up-time': '14 days, 22 hours, 34 minutes, 13 '
                                       'seconds',
                            'version-info': {'build': 7,
                                             'major': [15, 1],
                                             'minor': ['6'],
                                             'type': 'R'}}],
            'platform': 'MX480',
            'platform-info': [{'name': 're0', 'platform': 'MX480'},
                              {'name': 're1', 'platform': 'MX480'}],
            'product': 'MX',
            'release': '19.4I20190809_0730_madhus',
            'serial-number': 'xxxx'}},
 {'device-id': 'node1', 'facts': {}}]

使用DevicegroupSchema和提供的API添加设备组

fromjnpr.healthbotimportDeviceGroupSchema
dgs=DeviceGroupSchema(device_group_name="edge",devices=['demo'])

我们也可以在创建schema object

dgs.description="All devices on the edge"

现在使用提供的API添加设备组

print(hb.device_group.add(dgs))
True

让我们看看使用Schema

 1> Helps with any missing paramters
 2> Checks for any rule associated with given params
# Error for missing mandatory parametersdgs=DeviceGroupSchema()
---------------------------------------------------------------------------

ValueError                                Traceback (most recent call last)

<ipython-input-39-4d61d231fd38> in <module>
      1 # Error for missing mandatory parameters
      2 
----> 3 dgs = DeviceGroupSchema()


~/Coding/git.juniper.net.iceberg/healthbot-py-client/lib/jnpr/healthbot/swagger/models/device_group_schema.py in __init__(self, authentication, description, device_group_name, devices, logging, native_gpb, notification, playbooks, reports, retention_policy, variable)
     85         if description is not None:
     86             self.description = description
---> 87         self.device_group_name = device_group_name
     88         if devices is not None:
     89             self.devices = devices


~/Coding/git.juniper.net.iceberg/healthbot-py-client/lib/jnpr/healthbot/swagger/models/device_group_schema.py in device_group_name(self, device_group_name)
    168         """
    169         if device_group_name is None:
--> 170             raise ValueError("Invalid value for `device_group_name`, must not be `None`")  # noqa: E501
    171         if device_group_name is not None and len(device_group_name) > 64:
    172             raise ValueError("Invalid value for `device_group_name`, length must be less than or equal to `64`")  # noqa: E501


ValueError: Invalid value for `device_group_name`, must not be `None`
# Error for not following rule for give parameterdgs=DeviceGroupSchema(device_group_name="edge group")
---------------------------------------------------------------------------

ValueError                                Traceback (most recent call last)

<ipython-input-40-8617b5d8e365> in <module>
      1 # Error for not following rule for give parameter
      2 
----> 3 dgs = DeviceGroupSchema(device_group_name="edge group")


~/Coding/git.juniper.net.iceberg/healthbot-py-client/lib/jnpr/healthbot/swagger/models/device_group_schema.py in __init__(self, authentication, description, device_group_name, devices, logging, native_gpb, notification, playbooks, reports, retention_policy, variable)
     85         if description is not None:
     86             self.description = description
---> 87         self.device_group_name = device_group_name
     88         if devices is not None:
     89             self.devices = devices


~/Coding/git.juniper.net.iceberg/healthbot-py-client/lib/jnpr/healthbot/swagger/models/device_group_schema.py in device_group_name(self, device_group_name)
    172             raise ValueError("Invalid value for `device_group_name`, length must be less than or equal to `64`")  # noqa: E501
    173         if device_group_name is not None and not re.search('^[a-zA-Z][a-zA-Z0-9_-]*$', device_group_name):  # noqa: E501
--> 174             raise ValueError("Invalid value for `device_group_name`, must be a follow pattern or equal to `/^[a-zA-Z][a-zA-Z0-9_-]*$/`")  # noqa: E501
    175 
    176         self._device_group_name = device_group_name


ValueError: Invalid value for `device_group_name`, must be a follow pattern or equal to `/^[a-zA-Z][a-zA-Z0-9_-]*$/`
# Now we are in compliance with rulesdgs=DeviceGroupSchema(device_group_name="edge")
^{pr51}$

我们也可以将所有Schema参数传递给add_uAPI,在内部它将使用这些参数来创建Schema

print(hb.device_group.add(device_group_name="edge",description="All devices on the edge",devices=['demo']))hb.commit()
^{pr53}$ ^{pr54}$ ^{pr55}$
hb.device_group.delete('edge',force=True)
True

将现有设备添加到现有组

hb.device_group.add_device_in_group('vmx','edge')
True
obj=hb.device_group.get('edge')print(obj)
^{pr61}$
obj.devices
['vmx', 'demo']

获取所有设备组的详细信息

print(hb.device_group.get())
[{'authentication': None,
 'description': None,
 'device_group_name': 'real',
 'devices': ['edge'],
 'logging': None,
 'native_gpb': None,
 'notification': {},
 'playbooks': ['phyport'],
 'reports': [],
 'retention_policy': None,
 'variable': [{'@': {'changed-seconds': 1563348601},
               'instance-id': 'ge-1-0-0',
               'playbook': 'phyport',
               'rule': 'external/interface-info',
               'variable-value': [{'name': 'interface_name',
                                   'value': 'ge-1/0/0'}]},
              {'@': {'changed-seconds': 1563348601},
               'instance-id': 'ge-1-0-1',
               'playbook': 'phyport',
               'rule': 'external/interface-info',
               'variable-value': [{'name': 'interface_name',
                                   'value': 'ge-1/0/1'}]}]}, {'authentication': None,
 'description': 'UBS Demo',
 'device_group_name': 'QFabric',
 'devices': ['node1'],
 'logging': None,
 'native_gpb': None,
 'notification': {},
 'playbooks': [],
 'reports': [],
 'retention_policy': None,
 'variable': []}, {'authentication': {'password': {'password': 'xxxx',
                                 'username': 'xxxx'}},
 'description': None,
 'device_group_name': 'EVO_CORE',
 'devices': ['EVO'],
 'logging': None,
 'native_gpb': None,
 'notification': {},
 'playbooks': [],
 'reports': [],
 'retention_policy': None,
 'variable': []}, {'authentication': {'password': {'password': 'xxxx',
                                 'username': 'xxxx'}},
 'description': None,
 'device_group_name': 'vmx_db',
 'devices': ['core_db'],
 'logging': {'log-level': 'critical'},
 'native_gpb': None,
 'notification': {},
 'playbooks': [],
 'reports': [],
 'retention_policy': None,
 'variable': []}, {'authentication': None,
 'description': 'All devices on the edge',
 'device_group_name': 'edge',
 'devices': ['vmx', 'demo'],
 'logging': {'log-level': 'warn'},
 'native_gpb': None,
 'notification': {},
 'playbooks': [],
 'reports': [],
 'retention_policy': None,
 'variable': [{'@': {'changed-seconds': 1565668543},
               'instance-id': 'HbEZ-instance',
               'playbook': 'forwarding-table-summary',
               'rule': 'protocol.routesummary/check-fib-summary'},
              {'@': {'changed-seconds': 1565669467},
               'instance-id': 'HbEZ-instance',
               'playbook': 'icmp-probe',
               'rule': 'protocol.icmp/check-icmp-statistics'}]}, {'authentication': None,
 'description': 'learning',
 'device_group_name': 'Core',
 'devices': ['vmx'],
 'logging': None,
 'native_gpb': {'ports': [22000]},
 'notification': {},
 'playbooks': ['icmp-probe', 'rca-ospf-playbook'],
 'reports': [],
 'retention_policy': None,
 'variable': [{'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'interface.statistics/check-host-loopback-status',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'linecard.fpc/check-fpc-memory',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'linecard.ospf/check-ddos-statistics',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'linecard.statistics/check-center-chip-host-path',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'linecard.statistics/check-cm-error-table',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'linecard.statistics/check-fpc-cpu-scheduler-info',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'linecard.statistics/check-fpc-threads',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'linecard.statistics/check-fpc-utilization-information',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'linecard.statistics/check-ithrottle',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'linecard.statistics/check-ithrottle-statistics',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'linecard.statistics/check-jnh-exceptions',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'linecard.statistics/check-jnh-interface-statistics',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'linecard.statistics/check-linecard-ethernet-statistics',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'linecard.statistics/check-pci-error-counters',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'linecard.statistics/check-pfe-traffic-statistics',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'linecard.statistics/check-pre-classifier-dropped-packets',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'linecard.statistics/check-traffic-offload-engine-status',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'protocol.infra/check-task-io-drops',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'protocol.infra/check-task-memory-usage',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'protocol.ospf/check-ospf-forwarding-table',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'protocol.ospf/check-ospf-io-statistics-information',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'protocol.ospf/check-ospf-neighbor-information',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'protocol.ospf/check-ospf-statistics-information',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'protocol.ospf/fpc-link-stats',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'protocol.ospf/pfe-ddos-policer',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'system.statistics/check-routing-engine-cpu-utilization',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'system.statistics/check-system-input-queues',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'system.statistics/check-system-output-queues',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'system.statistics/check-system-statistics-ip',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'system.statistics/check-system-storage-capacity',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'system.statistics/check-system-virtual-memory-information',
               'variable-value': []},
              {'@': {'changed-seconds': 1564722219},
               'instance-id': 'test1',
               'playbook': 'rca-ospf-playbook',
               'rule': 'system.statistics/check-version',
               'variable-value': []},
              {'@': {'changed-seconds': 1565263889},
               'instance-id': 'set1',
               'playbook': 'icmp-probe',
               'rule': 'protocol.icmp/check-icmp-statistics',
               'variable-value': [{'name': 'host-var', 'value': '10.221.11.11'},
                                  {'name': 'count-var', 'value': '2'}]}]}]

我们还可以更新任何给定的设备组

print(hb.device_group.get('edge'))
^{pr61}$
dgs=hb.device_group.get('edge')dgs.devices.append('vmx')hb.device_group.update(dgs)
True
# Check for devices listdgs=hb.device_group.get('edge')print(dgs)
^{pr61}$
dgs.devices=['edge']hb.device_group.update(dgs)
True
dgs=hb.device_group.get('edge')print(dgs)
{'authentication': None,
 'description': 'All devices on the edge',
 'device_group_name': 'edge',
 'devices': ['edge'],
 'logging': {'log-level': 'warn'},
 'native_gpb': None,
 'notification': {},
 'playbooks': [],
 'reports': [],
 'retention_policy': None,
 'variable': [{'@': {'changed-seconds': 1565668543},
               'instance-id': 'HbEZ-instance',
               'playbook': 'forwarding-table-summary',
               'rule': 'protocol.routesummary/check-fib-summary'},
              {'@': {'changed-seconds': 1565669467},
               'instance-id': 'HbEZ-instance',
               'playbook': 'icmp-probe',
               'rule': 'protocol.icmp/check-icmp-statistics'}]}
# can also update by passing Device Group Schema kwargsdgs=hb.device_group.get('edge')pprint(dgs)fromjnpr.healthbotimportDevicegroupSchemaLogginglogSchema=DevicegroupSchemaLogging('warn')hb.device_group.update(device_group_name='edge',logging=logSchema)
^{pr77}$ ^{pr78}$
hb.device_group.delete('edge')
True
hb.device.delete('demo')
True
# Lets commit all the changeshb.commit()
True

添加网络组

hb.network_group.add(network_group_name="HbEZ")
True
^{pr87}$ ^{pr88}$

使用架构添加网络组

^{pr89}$
ngs=NetworkGroupSchema(network_group_name="HbEZ")
hb.network_group.add(ngs)
True
^{pr93}$
{'description': None,
 'network_group_name': 'HbEZ',
 'notification': {},
 'playbooks': [],
 'reports': [],
 'variable': None}

用例:规则

^{pr95}$ ^{pr96}$

新规则3添加> ^{pr97}$

设置规则架构参数

^{pr98}$ ^{pr99}$
rs.variable=[{'description':'Linecard Buffer Memory usage threshold value','name':'fpc-buffer-usage-threshold','type':'int','value':'80'},{'description':'Linecard CPU usage threshold value','name':'fpc-cpu-usage-threshold','type':'int','value':'80'},{'description':'Linecard Heap Memory usage threshold value','name':'fpc-heap-usage-threshold','type':'int','value':'80'}]
^{pr101}$

如果主题名不存在,首先它将创建给定主题

hb.rule.add('hbez',schema=rs)
True
# hb.rules.delete_rule(topic_name='external', rule_name="hbez-fpc-heap-utilization")

剧本:使用案例

pprint(hb.playbook.get('linecard-kpis-playbook'))
{'description': 'Playbook checks linecard health i.e. cpu, memory and CM '
                'errors',
 'playbook_name': 'linecard-kpis-playbook',
 'rules': ['linecard.cm-events/check-cm-events',
           'linecard.fpc/check-fpc-cpu',
           'linecard.fpc/check-fpc-memory'],
 'synopsis': 'Linecards key performance indicators'}
fromjnpr.healthbot.modules.playbooksimportPlaybookSchema
pbs=PlaybookSchema(playbook_name="HbEZ-example")
^{pr109}$
pbs.rules=['hbez/hbez-fpc-heap-utilization']
hb.playbook.add(pbs)
True
hb.playbook.delete(playbook_name="HbEZ-example")
True

用例:健康

pprint(hb.health.get_device_health('edge'))
{'children': [{'children': [{'children': [], 'name': 'external'}],
               'name': 'real'}],
 'color': None,
 'data': None,
 'name': 'edge',
 'timestamp': None}
pprint(hb.health.get_device_group_health('real'))
^118{pr}$

用例:数据库

This we might need to take it off
print(hb.tsdb.query("show databases"))
^{pr121}$
obj=hb.tsdb.query('select * from "protocol-eventd-host/check-host-traffic/packet-loss" limit 10',database='Core:vmx')pprint(obj.raw)
{'statement_id': 0}
print(hb.version)
2.0.1
### Load any helper file
^{pr127}$

用例:通知

fromjnpr.healthbotimportNotificationSchemafromjnpr.healthbotimportNotificationSchemaSlackns=NotificationSchema(notification_name='HbEZ-notification')ns.description="example of adding notification via API"nss=NotificationSchemaSlack(channel="HbEZ",url='http://testing')ns.slack=nsshb.settings.notification.add(ns)
True
print(hb.settings.notification.get())
[{'description': 'example of adding notification via API',
 'http_post': None,
 'kafka_publish': None,
 'notification_name': 'HbEZ-notification',
 'slack': {'channel': 'HbEZ', 'url': 'http://testing'}}]
pprint(hb.settings.notification.delete('HbEZ-notification'))
True

用例:设置

fromjnpr.healthbotimportRetentionPolicySchemarps=RetentionPolicySchema(retention_policy_name='HbEZ-testing')hb.settings.retention_policy.add(rps)
True
print(hb.settings.retention_policy.get())
^{pr137}$
fromjnpr.healthbotimportSchedulerSchemasc=SchedulerSchema(name='HbEZ-schedule',repeat={'every':'week'},start_time="2019-07-22T05:32:23Z")hb.settings.scheduler.add(sc)fromjnpr.healthbotimportDestinationSchemads=DestinationSchema(name='HbEZ-destination',email={'id':'nitinkr@juniper.net'})hb.settings.destination.add(ds)fromjnpr.healthbotimportReportSchemars=ReportSchema(name="HbEZ-report",destination=['HbEZ-destination'],format="html",schedule=["HbEZ-schedule"])hb.settings.report.add(rs)
True

用例:PlayBook实例

fromjnpr.healthbot.modules.playbooksimportPlayBookInstanceBuilder# case where we dont need to set any variablepbb=PlayBookInstanceBuilder(hb,'forwarding-table-summary','HbEZ-instance','Core')pbb.apply()#hb.commit()
True

当我们需要为playbook实例中的给定设备/组设置任何规则变量时

fromjnpr.healthbot.modules.playbooksimportPlayBookInstanceBuilderpbb=PlayBookInstanceBuilder(hb,'forwarding-table-summary','HbEZ-instance','Core')variable=pbb.rule_variables["protocol.routesummary/check-fib-summary"]variable.route_address_family='pqr'variable.route_count_threshold=100# Apply variable to given device(s)pbb.apply(device_ids=['vmx'])#clear all the variable if you want to set it something else for group or other device(s)pbb.clear()variable=pbb.rule_variables["protocol.routesummary/check-fib-summary"]variable.route_address_family='abc'variable.route_count_threshold=200pbb.apply()#hb.commit()
True

许可证

Apache 2.0版

贡献者

Juniper Networks正在积极参与并维护此回购。请联系healthbot黑客juniper.net公司对于任何查询。在

贡献者:

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
序列化反序列化java。awt。颜色>java。木卫一。InvalidClassException   java禁用多个日期范围jDateChooser   java为什么我的特例apper会被扔进泽西/灰熊?   JavaIntelliJ比较两个覆盖率数据   java什么是servletsdefault。你怎么办?   单击几下libgdx后java按钮没有响应   使用java将字符串转换为JSONArray   文件系统在java中刷新fileSystemViewer   java如何在hibernate中避免脏检查   java奇怪的问题,带有分号和“无法解决…”   java将值从子面板传递到父面板   HTML JTextPane CSS的Java FontSizeAction   java文件代码神秘地变成了一堆(0000)