%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/engines/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/engines/napalm_syslog.pyo

�
���^c@@s%dZddlmZmZmZddlZddlmZy"ddlZddl	Ze
ZWnek
rye
ZnXddljjZddlZddlZeje�ZdZd�Zd�Zdd	d
d�Zied6ed6Zdd	d
d	d
e
dddddddd�
ZdS(u7
NAPALM syslog engine
====================

.. versionadded:: 2017.7.0

An engine that takes syslog messages structured in
OpenConfig_ or IETF format
and fires Salt events.

.. _OpenConfig: http://www.openconfig.net/

As there can be many messages pushed into the event bus,
the user is able to filter based on the object structure.

Requirements
------------

- `napalm-logs`_

.. _`napalm-logs`: https://github.com/napalm-automation/napalm-logs

This engine transfers objects from the napalm-logs library
into the event bus. The top dictionary has the following keys:

- ``ip``
- ``host``
- ``timestamp``
- ``os``: the network OS identified
- ``model_name``: the OpenConfig or IETF model name
- ``error``: the error name (consult the documentation)
- ``message_details``: details extracted from the syslog message
- ``open_config``: the OpenConfig model

The napalm-logs transfers the messages via widely used transport
mechanisms such as: ZeroMQ (default), Kafka, etc.

The user can select the right transport using the ``transport``
option in the configuration.

:configuration: Example configuration

    .. code-block:: yaml

        engines:
          - napalm_syslog:
              transport: zmq
              address: 1.2.3.4
              port: 49018

:configuration: Configuration example, excluding messages from IOS-XR devices:

    .. code-block:: yaml

        engines:
          - napalm_syslog:
              transport: kafka
              address: 1.2.3.4
              port: 49018
              os_blacklist:
                - iosxr

Event example:

.. code-block:: json

    {
        "_stamp": "2017-05-26T10:03:18.653045",
        "error": "BGP_PREFIX_THRESH_EXCEEDED",
        "host": "vmx01",
        "ip": "192.168.140.252",
        "message_details": {
            "date": "May 25",
            "host": "vmx01",
            "message": "192.168.140.254 (External AS 65001): Configured maximum prefix-limit threshold(22) exceeded for inet-unicast nlri: 28 (instance master)",
            "pri": "28",
            "processId": "2957",
            "processName": "rpd",
            "tag": "BGP_PREFIX_THRESH_EXCEEDED",
            "time": "20:50:41"
        },
        "model_name": "openconfig_bgp",
        "open_config": {
            "bgp": {
                "neighbors": {
                    "neighbor": {
                        "192.168.140.254": {
                            "afi_safis": {
                                "afi_safi": {
                                    "inet": {
                                        "afi_safi_name": "inet",
                                        "ipv4_unicast": {
                                            "prefix_limit": {
                                                "state": {
                                                    "max_prefixes": 22
                                                }
                                            }
                                        },
                                        "state": {
                                            "prefixes": {
                                                "received": 28
                                            }
                                        }
                                    }
                                }
                            },
                            "neighbor_address": "192.168.140.254",
                            "state": {
                                "peer_as": 65001
                            }
                        }
                    }
                }
            }
        },
        "os": "junos",
        "timestamp": "1495741841"
    }

To consume the events and eventually react and deploy a configuration changes
on the device(s) firing the event, one is able to identify the minion ID, using
one of the following alternatives, but not limited to:

- :mod:`Host grains <salt.grains.napalm.host>` to match the event tag
- :mod:`Host DNS grain <salt.grains.napalm.host_dns>` to match the IP address in the event data
- :mod:`Hostname grains <salt.grains.napalm.hostname>` to match the event tag
- :ref:`Define static grains <static-custom-grains>`
- :ref:`Write a grains module <writing-grains>`
- :ref:`Targeting minions using pillar data <targeting-pillar>` - The user can
  configure certain information in the Pillar data and then use it to identify
  minions

Master configuration example, to match the event and react:

.. code-block:: yaml

    reactor:
      - 'napalm/syslog/*/BGP_PREFIX_THRESH_EXCEEDED/*':
        - salt://increase_prefix_limit_on_thresh_exceeded.sls

Which matches the events having the error code ``BGP_PREFIX_THRESH_EXCEEDED``
from any network operating system, from any host and reacts, executing the
``increase_prefix_limit_on_thresh_exceeded.sls`` reactor, found under
one of the :conf_master:`file_roots` paths.

Reactor example:

.. code-block:: yaml

    increase_prefix_limit_on_thresh_exceeded:
      local.net.load_template:
        - tgt: "hostname:{{ data['host'] }}"
        - tgt_type: grain
        - kwarg:
            template_name: salt://increase_prefix_limit.jinja
            openconfig_structure: {{ data['open_config'] }}

The reactor in the example increases the BGP prefix limit
when triggered by an event as above. The minion is matched using the ``host``
field from the ``data`` (which is the body of the event), compared to the
:mod:`hostname grain <salt.grains.napalm.hostname>` field. When the event
occurs, the reactor will execute the
:mod:`net.load_template <salt.modules.napalm_network.load_template>` function,
sending as arguments the template ``salt://increase_prefix_limit.jinja`` defined
by the user in their environment and the complete OpenConfig object under
the variable name ``openconfig_structure``. Inside the Jinja template, the user
can process the object from ``openconfig_structure`` and define the bussiness
logic as required.
i(tabsolute_importtprint_functiontunicode_literalsN(tzmqu
napalm_syslogcC@ststrtdfStS(u0
    Load only if napalm-logs is installed.
    u]napalm_syslog could not be loaded.             Please install napalm-logs library amd ZeroMQ.(tHAS_NAPALM_LOGSRtFalsetTrue(((s>/usr/lib/python2.7/site-packages/salt/engines/napalm_syslog.pyt__virtual__�scK@sxtj�}|jtj�}tjjj|�r?t|_	n|j
djd|d|��|jtj
d�|jS(Nutcp://{addr}:{port}taddrtportt(RtContexttsockettSUBtsalttutilstnetworktis_ipv6Rtipv6tconnecttformatt
setsockoptt	SUBSCRIBEtrecv(taddressR	tkwargstcontextR((s>/usr/lib/python2.7/site-packages/salt/engines/napalm_syslog.pyt_zmq�s
uzmqu0.0.0.0iy�cK@s9|tkr%tjd|�d}nt||||�S(Nu.Invalid transport: %s. Falling back to ZeroMQ.uzmq(tTRANSPORT_FUN_MAPtlogterror(tnameRR	R((s>/usr/lib/python2.7/site-packages/salt/engines/napalm_syslog.pyt_get_transport_recv�s	uzeromqiz�c
C@s�|s>|stjd�dStjj|d|d|�}
ntd|d|d|�}|svtjddt�dSt}tdd	kr�t}nx,tr�tj	d
�|�}tj	d�tj	|�|s�|
j
|�}ntjj|�}y8|d}|s|rQtjj
j|d
|d|�}|sQtjd|�w�qQn|d}|
sg|	r�tjj
j|d
|	d|
�}|s�tjd|�w�q�n|jd�p�|jd�}|s�|rtjj
j|d
|d|�}|stjd|�w�qndjd|d|d|�}Wn6tk
rh}tjddt�tj|�q�nXtj	d|�tj	|�|r�tjttd�j||�q�td||�q�WdS(u�
    Listen to napalm-logs and publish events into the Salt event bus.

    transport: ``zmq``
        Choose the desired transport.

        .. note::
            Currently ``zmq`` is the only valid option.

    address: ``0.0.0.0``
        The address of the publisher, as configured on napalm-logs.

    port: ``49017``
        The port of the publisher, as configured on napalm-logs.

    auth_address: ``0.0.0.0``
        The address used for authentication
        when security is not disabled.

    auth_port: ``49018``
        Port used for authentication.

    disable_security: ``False``
        Trust unencrypted messages.
        Strongly discouraged in production.

    certificate: ``None``
        Absolute path to the SSL certificate.

    os_whitelist: ``None``
        List of operating systems allowed. By default everything is allowed.

    os_blacklist: ``None``
        List of operating system to be ignored. Nothing ignored by default.

    error_whitelist: ``None``
        List of errors allowed.

    error_blacklist: ``None``
        List of errors ignored.

    host_whitelist: ``None``
        List of hosts or IPs to be allowed.

    host_blacklist: ``None``
        List of hosts of IPs to be ignored.
    u2Please use a certificate, or disable the security.NRR	RuUnable to start the enginetexc_infou__roleumasteru+Waiting for napalm-logs to send anything...uReceived from napalm-logs:uost	whitelistt	blacklistu*Ignoring NOS %s as per whitelist/blacklistuerroru,Ignoring error %s as per whitelist/blacklistuhostuipu4Ignoring messages from %s as per whitelist/blacklistu!napalm/syslog/{os}/{error}/{host}tosRthostu)Missing keys from the napalm-logs object:uSending event %susock_diru
event.send(Rtcriticaltnapalm_logsRt
ClientAuthR RRt__opts__tdebugtdecrypttunserializeRtstringutilstcheck_whitelist_blacklisttinfotgetRtKeyErrortwarningteventtget_master_eventt
fire_eventt__salt__(t	transportRR	tauth_addresst	auth_porttdisable_securitytcertificatetos_whitelisttos_blacklistterror_whitelistterror_blacklistthost_whitelistthost_blacklisttauthttransport_recv_funtmastert
raw_objecttdict_objecttevent_ostvalid_ostevent_errortvalid_errort
event_hostt
valid_hostttagtkerr((s>/usr/lib/python2.7/site-packages/salt/engines/napalm_syslog.pytstart�s�<
			
	


		
					


	

(t__doc__t
__future__RRRtloggingtsalt.utils.zeromqRR'tnapalm_logs.utilsRRtImportErrorRtsalt.utils.eventRR3tsalt.utils.networkRtsalt.utils.stringutilst	getLoggert__name__Rt__virtualname__RRR RtNoneRO(((s>/usr/lib/python2.7/site-packages/salt/engines/napalm_syslog.pyt<module>�sF


	
	



Zerion Mini Shell 1.0