Sending push notifications to my phone

I had an XMPP server which I used to send Nagios notifications to my phone using XMPP messages. I also hoped to use it for chatting with people, but since everyone uses locked in systems like Facebook and Skype that don't support federation I decided to stop using XMPP.

I decided to use the service Pushover.net instead which is has a mobile app for receiving push notifications.

It works great, you register you app on the website and your device from your mobile. After that it's just a simple HTTP POST request away from sending push messages.

I created a small python script which I use in my Nagios system that sends the alert through Pushover. It's in my github script repo.

Send-Pushover (Check the repo for the latest version)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python3

import argparse
import requests
import sys

def push_message(message, app, user):
        data = { "token": app, "user": user, "message": message }
        r = requests.post("https://api.pushover.net/1/messages.json", params=data)

def main(argv):
    parser = argparse.ArgumentParser(description="Push message with Pushover.net")
    parser.add_argument('-a', dest='app_id', required=True, help="Application ID")
    parser.add_argument('-u', dest='user_id', required=True, help="User ID")
    parser.add_argument('-m', dest='message', required=False, default='', help="Message to send, can also be read from stdin")
    args = parser.parse_args(argv)

    if (args.message == '') and not sys.stdin.isatty():
        for line in sys.stdin:
            args.message = args.message + line

    push_message(args.message, args.app_id, args.user_id)

if __name__ == "__main__":
    main(sys.argv[1:])

Awstats only builds main report

I am using awstats on my blog to generate visitor statistics from my web server logs. I installed awstats from the ubuntu repositories, and that package creates a scheduled cron job for building the static report pages.

The cron job executes /usr/share/awstats/tools/buildstatic.sh which in turn executes awstats_buildstaticpages.pl.

Awstats_buildstaticpages.pl is a script which is supposed to create all report pages, but there seems to be an issue with this script. It seems the script does not load the default values for the Show* config options.

The Show config values are used to set which report pages to generate.

So in order to force the script to build all the reports, you need to explicitly add the Show* options to your awstats config file.

Taiga, love your project

So I have been looking for a agile project management tool for some time now.

I recently found Taiga at https://taiga.io

It is free and open source built on Python/Django and AngularJS. If you don't want to host it yourself Taiga also offers cloud based hosting free for public projects and a small montly fee for private projects, but for now during the beta period it's free.

It has support for both Scrum and Kanban, and has an issue tracker and simple wiki with markdown syntax.

The interface is nice and easy to understand.

There is a team page where you can see how active the team members are through a type of "gamification" where you get a higher score depending on how many tasks etc that you solve.

So if you are looking for a project management system you should give Taiga a try.

Get used diskspace on all servers

I had the need to get the used disk space on all our servers today. VMware only shows the peak disk usage and don't account for when files are removed and disk usage is lowered, those metrics was not useful.

To solve this I used SaltStack which we use to configure our servers. The following command returns the information about each disk on the server, like size and used space. The output is saved to disk_usage.txt.

salt "*" disk.usage > disk_usage.txt

The output does not give a good overview of the total disk usage on the server since each disk is displayed individually, and the output format is not ready to be imported in a spreadsheet.

So I created this Python script which parses the disk_usage.txt file and returns a list of server name and the total used space.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import re

with open("disk_usage.txt", "r") as f:
    result = {}
    hostname = ""
    used_space = 0
    get_next_line = False
    current_mount = None
    for line in f:
        if get_next_line:
            size = '\n'.join(line.splitlines()).lstrip(' ')
            get_next_line = False
            if re.match("[0-9]+", size):
                if current_mount.startswith('/'):
                    used_space += int(size) / 1024 / 1024
                else:
                    used_space += int(size) / 1024 / 1024 / 1024

        if re.match("^[a-zA-Z0-9].*", line):
            if hostname is not "":
                print("{}\t{}".format(hostname, used_space))
            hostname = '\n'.join(line.splitlines()).rstrip(':')
            used_space = 0
        if re.match("^[  ]{4}[A-Z/]+", line):
            current_mount = line.lstrip(' ')
        if re.match("^[  ]{8}used:$", line):
            get_next_line = True

The script has to take into account that Salt seems to return the used disk space in kilobytes on Linux servers, but in just bytes on Windows servers.