Code Monkey home page Code Monkey logo

napalm-automation / napalm-logs Goto Github PK

View Code? Open in Web Editor NEW
141.0 16.0 45.0 1.75 MB

Cross-vendor normalisation for network syslog messages, following the OpenConfig and IETF YANG models

Home Page: https://napalm-logs.readthedocs.io/en/latest/

License: Apache License 2.0

Python 99.09% Shell 0.07% Makefile 0.61% Dockerfile 0.23%
napalm syslog zeromq engine event-driven event-driven-automation event-driven-architecture kafka transport syslog-messages

napalm-logs's Introduction

napalm-logs

napalm-logs is a Python library that listens to syslog messages from network devices and returns structured data following the OpenConfig or IETF YANG models.

The outgoing objects are published via ZeroMQ, Kafka, or other usual transport options. It is easy enough to switch between transports and pluggable to add others such as Google Datastore, RabbitMQ, etc.

Similarly, the syslog messages can be received via UDP, TCP, or different services, such as Kafka, etc.

New platforms can be easily added, just referencing the path to the YAML configuration file.

Requirements

  • PyYAML
  • PyZMQ
  • PyNaCl
  • u-msgpack-python

Output object example

{
  "yang_message": {
    "bgp": {
      "neighbors": {
        "neighbor": {
          "192.168.140.254": {
            "state": {
              "peer_as": "65001"
            },
            "afi_safis": {
              "afi_safi": {
                "inet4": {
                  "state": {
                    "prefixes": {
                      "received": 141
                    }
                  },
                  "ipv4_unicast": {
                    "prefix_limit": {
                      "state": {
                        "max_prefixes": 140
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "message_details": {
    "processId": "2902",
    "facility": 18,
    "severity": 5,
    "hostPrefix": null,
    "pri": "149",
    "processName": "rpd",
    "host": "vmx01",
    "tag": "BGP_PREFIX_THRESH_EXCEEDED",
    "time": "14:03:12",
    "date": "Jun 21",
    "message": "192.168.140.254 (External AS 65001): Configured maximum prefix-limit threshold(140) exceeded for inet4-unicast nlri: 141 (instance master)"
  },
  "timestamp": 1498050192,
  "facility": 18,
  "ip": "127.0.0.1",
  "host": "vmx01",
  "yang_model": "openconfig-bgp",
  "error": "BGP_PREFIX_THRESH_EXCEEDED",
  "os": "junos",
  "severity": 5
}

Documentation

Please check the official documentation for more detailed information.

Installation

pip install napalm-logs

napalm-logs's People

Contributors

aaronjohnson avatar alopes79 avatar bigpick avatar bittsi avatar chonty avatar gbieli avatar ichabond avatar inetant avatar johanek avatar koaxiel avatar lampwins avatar lspgn avatar luke-orden avatar mirceaulinic avatar nathancatania avatar tim-fiola avatar tkinet avatar tmenari avatar wasabi222 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

napalm-logs's Issues

List of possible OSPF messages (adjacency change reason)

The adjacency reason message is simply a text currently. We should probably start building a list of the possible messages and map them into a standard structure rather than random bits of text. This can eventually be merged into the official openconfig-ospf model later - TDB. For the time being, let's just identify what messages we see. @lampwins could you start here a list of messages you've seen so far?

Clients do not reconnect after server restarts causing crypt issues

If the server restarts after the client has connected, then the client is left with old crypto info:

Traceback (most recent call last):
  File "/home/luke/git/napalm-logs/test-listen.py", line 19, in <module>
    decrypted = napalm_logs.utils.decrypt(data, vk, pk)
  File "/home/luke/git/napalm-logs/napalm_logs/utils/__init__.py", line 77, in decrypt
    raise BadSignatureException('Signature was forged or corrupt')
napalm_logs.exceptions.BadSignatureException: Signature was forged or corrupt

Therefore we need to have the clients restart, or allow them to use the old crypo info (not ideal)

Python profiler should reference the module rather the function

Not only that there's a bug messing with global vars, but we could potentially have both index and message profiler in the same module (as some complex and obscure messages might belong to a class that don't use a generic prefix, but something very particular).

Authentication system & new cli script to allow/block clients

Start new child process serving auth requests
Implies new arg for auth port (default: publish + 1)
Authentication can be optional (if disabled, won't start the auth process). If disabled, accept and serve any client.
Main goal: the client has to be sure that it can trust the publisher
RSA and AES
The CLI script plugged to the authentication process through zmq IPC

The output show details of previous messages

Example

1st input:

<149>Mar 30 12:45:19  edge01.xyz01 rpd[1234]: BGP_PREFIX_THRESH_EXCEEDED: 1.2.3.4 (External AS 123): Configured maximum prefix-limit threshold(160) exceeded for inet-unicast nlri: 181 (instance master)

1st Output

{'message_details': {'processId': '1234', 'pri': '149', 'processName': 'rpd', 'host': 'edge01.xyz01', 'tag': 'BGP_PREFIX_THRESH_EXCEEDED', 'time': '12:45:19', 'date': 'Mar 30', 'message': '1.2.3.4 (External AS 123): Configured maximum prefix-limit threshold(160) exceeded for inet-unicast nlri: 181 (instance master)'}, 'open_config': {'bgp': {'neighbors': {'neighbor': {u'1.2.3.4': {'state': {'peer_as': 123}, 'afi_safis': {'afi_safi': {u'inet': {'state': {'prefixes': {'received': 181}}, 'afi_safi_name': u'inet', 'ipv4_unicast': {'prefix_limit': {'state': {'max_prefixes': 160}}}}}}, 'neighbor_address': u'1.2.3.4'}}}}}, 'ip': '127.0.0.1', 'error': 'BGP_PREFIX_THRESH_EXCEEDED', 'host': 'edge01.xyz01', 'timestamp': '1490874319', 'os': 'junos', 'model_name': 'openconfig_bgp'}

2nd input:

<149>Mar 30 12:45:19  edge01.xyz01 rpd[1234]: BGP_PREFIX_THRESH_EXCEEDED: 5.6.7.8 (External AS 123): Configured maximum prefix-limit threshold(160) exceeded for inet-unicast nlri: 181 (instance master)

2nd Output:

{'message_details': {'processId': '1234', 'pri': '149', 'processName': 'rpd', 'host': 'edge01.xyz01', 'tag': 'BGP_PREFIX_THRESH_EXCEEDED', 'time': '12:45:19', 'date': 'Mar 30', 'message': '5.6.7.8 (External AS 123): Configured maximum prefix-limit threshold(160) exceeded for inet-unicast nlri: 181 (instance master)'}, 'open_config': {'bgp': {'neighbors': {'neighbor': {u'1.2.3.4': {'state': {'peer_as': 123}, 'afi_safis': {'afi_safi': {u'inet': {'state': {'prefixes': {'received': 181}}, 'afi_safi_name': u'inet', 'ipv4_unicast': {'prefix_limit': {'state': {'max_prefixes': 160}}}}}}, 'neighbor_address': u'1.2.3.4'}, u'5.6.7.8': {'state': {'peer_as': 123}, 'afi_safis': {'afi_safi': {u'inet': {'state': {'prefixes': {'received': 181}}, 'afi_safi_name': u'inet', 'ipv4_unicast': {'prefix_limit': {'state': {'max_prefixes': 160}}}}}}, 'neighbor_address': u'5.6.7.8'}}}}}, 'ip': '127.0.0.1', 'error': 'BGP_PREFIX_THRESH_EXCEEDED', 'host': 'edge01.xyz01', 'timestamp': '1490874319', 'os': 'junos', 'model_name': 'openconfig_bgp'}

As you can see in the example the details of the 1st input are present, this is not intended.

Analysis

This is due to us caching the openconfig object, each time we load a new dict into the model this is stored in the cached version.

Revisit the structure of the CONFIGURATION_ERROR

Introduced in #168, we might need to evaluate on the long run if the current structure really makes sense cross-platform:

"system": {
    "configuration": {
        "error": true,
        "message": "Interface must already be defined under [edit interfaces]",
        "path": "[edit vlans VLANTEST l3-interface]",
        "statement": "l3-interface vlan.666"
    }
}

Add publish-unprocessed option

So it simply forwards the raw messages (with the sole advantage that is a little bit more structured, and the OS is identified + other details discovered).
This option should default to False.

Rename `tag` to `match_value`

Given that many messages won't have a unique identification tag (e.g., something like ROUTING-BGP-5-MAXPFX or at least bgp_read_message) we'll need to find other ways to match the message. In that case it might be confusing to use tag where there's not. But that's just a detail, looking for more feedback.

missing ietf syslog translation - undefined syslog message juniper

Hello,

it seems like napalm-logs is missing some kind of translation for the ietf standard.

  • Or an option to set syslog messages as ietf standard.
    I've configured the napalm-syslog server with basic configuration, no changes. Only set an ipaddress, port and disabled security.

Napalm-Logs is expecting the syslog message in following syntax:
<129>Oct 23 15:58:20 berlin cscript "message"

When i am looking at my tcpdump, juniper output as well as napalm log, the date format differs.

Juniper: Oct 23 15:58:20
TCP: 2017-10-23T16:02:38.950+02:00
napalm log: 2017-10-23T16:02:38.950+02:00

tcpdump:
Msg: 1 2017-10-23T16:02:38.950+02:00 berlin cscript - - - MX80 SN:XXXXX has booted 16.1R4-S4.3.
Uptime is 9 days, 23 hours, 7 minutes, 20 seconds

junos:
lab@berlin>show log messages | last 1
Oct 23 15:58:20 berlin cscript: MX80 SN:XXXXX has booted 16.1R4-S4.3. Uptime is 9 days, 23 hours, 3 minutes, 5 seconds

var/log/napalm/logs:
Dequeued message from <129>1 2017-10-23T16:02:38.950+02:00 berlin cscript - - - MX80 SN:XXXXX has booted 16.1R4-S4.3. Uptime is 9 days, 23 hours, 7 minutes, 20 seconds: 1508766848.76
2017-10-23 15:54:08,764,765 [napalm_logs.server][DEBUG ] Matching under junos
2017-10-23 15:54:08,765,765 [napalm_logs.server][DEBUG ] Matching using YAML-defined profiler:
2017-10-23 15:54:08,765,765 [napalm_logs.server][DEBUG ] <(\d+)>(\w+\s+\d+)\s+(\d\d:\d\d:\d\d)\s+(re\d.)?([^ ]+)\s+/?(\w+)[?(\d+)?]?:\s+([\w\s]+):(.*)
2017-10-23 15:54:08,765,765 [napalm_logs.server][DEBUG ] Match not found

Cheers!

Add `timezone` option

So you can run napalm-logs in non-sync'd locations; if the device does not send explicitly the timezone, it will use this one.
The option should default to UTC.
It may imply having another requirement, pytz.

Revisit internal pipeline system

We need to investigate more around zeromq/pyzmq#1009 in terms of latency and throughput over the IPC vs the multiprocessing Pipe.

I personally still believe that zmq should perform better. I also suspect that Pipe may miss messages when the buffer is full (send does not fail, hence we can't know whether the message has been queued or not). On the other hand, zmq does not miss any messages for sure, but we need to dig more into the delay issue.

Development documentation

Currently there is no documentation regarding development testing for napalm-logs. Ideally this should cover the testing methodology (or at least refer to the napalm-automation general topic on this). It should document how new test cases for configured messages should be setup.

Add Prometheus metrics

We should add metrics so one can easily see how many messages have been processed, how many per device, rate per hour etc

Optional security

Make security optional - there are cases when people would only need to send the data as-is to a log server, i.e. logstash etc. In that case, security is a bit overkill.
Ping @loverend - what do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.