Announcing AptWatcher

At Honeybadger we have been using apticron to keep on top of apt package updates for all servers. At first I had the apticron emails coming to my inbox, but at some point I decided I'd rather have them in our Slack notifications channel. Slack has a handy email app that can receive emails and post them to a channel, so I tried that. It worked, but I didn't love how the emails showed up as files, and there was all the noise of mail headers, etc., so I decided to whip up something that I would like a little more. Thus AptWatcher was born.

AptWatcher is a super simple app that I quickly threw together on a weekend to relay information about apt package updates from our servers to our Slack notifications channel. All it does it provide a HTTP endpoint that listens for a list of package names and versions that are ready to updated on a server. It compares that list to the list previously received from the server, and if any packages are found in the new list that weren't in the old list, it sends along those new packages to Slack via an incoming webhook.

That list of packages can be generated on the server by running this:

$ apt-get upgrade -s | grep ^Inst | awk '{ print $2,$3; }' | tr -d '[]'

That generates a list of packages that looks like this:

libxml2-dev 2.9.1+dfsg1-3ubuntu4.7
libxml2 2.9.1+dfsg1-3ubuntu4.7
libnl-genl-3-200 3.2.21-1ubuntu1.1
libnl-3-200 3.2.21-1ubuntu1.1

And that same list will show up in Slack when routed through AptWatcher:

Slack screenshot


Installation is as simple as clicking the Heroku button in the repo's README, and then adding a cron job to all your servers to report package changes to AptWatcher. Host records will get created automatically in AptWatcher as the reports arrive from the servers.

We use Ansible at Honeybadger to automate all the things, so I took the quick-and-dirty approach to replace apticron with AptWatcher:

$ ansible all -m apt -a 'pkg=apticron state=removed'
$ ansible all -m cron -a "name='Report pending apt changes' special_time=daily job='apt-get upgrade -s | grep ^Inst | awk \'{ print \$2,\$3; }\' | tr -d \'[]\' | curl -u user:pass --data-binary @- https://our.aptwatcher.url/report/\$(hostname) &> /dev/null'"

Once that's done, all you need to do is wait for the package reports to show up in Slack. Easy-peasy!