Getting Oxidized to Talk to Mattermost

Posted on 19 Jun 2018 by Marek 

It is no secret that we use Mattermost at Faelix — after all, it is a product we already support to be able to offer it to our customers. And like many network operators we use Oxidized to track and log changes to our routers and switches, even when those changes are made by automation tools.

As part of our move to using more ChatOps within the business I wanted to get visibility of network changes within our network operations channel in Mattermost. A quick and dirty script achieved this:


import os
import subprocess
import mattermostdriver


mm = mattermostdriver.Driver( { 'url': '',
                                'port': 443,
                                'scheme': 'https',
                                'token': MM_TOKEN,
                                } )

git = subprocess.Popen( [ "git",
                          '--git-dir=%s' % os.environ[ "OX_REPO_NAME" ],
                          os.environ[ "OX_REPO_COMMITREF" ],
                          ], stdout = subprocess.PIPE )
diff = 'utf-8', 'ignore' )

msg = '''\
Changes to `%s`:

``` diff
''' % ( os.environ[ "OX_NODE_NAME" ],
mm.posts.create_post( options = { 'channel_id': MM_CHANNEL_ID,
                                  'message': msg,
                                  } )

Configuring Oxidized was relatively straightforward too:

    type: exec
    events: [post_store]
    cmd: /home/oxidized/

That's all there was to it!