1. sending icinga 1.x notifications to slack

    i had some fun dealing with this. a good lot of my time is alloted to monitoring systems, so when i was told that a new team was going to play ping monkey i jumped on the opportunity to get them set up with everything they need to do the job coherently.

    previously we would send monitoring alarms to our hipchat server via hipsaint which works beautifully. we've moved to slack, so therefore our integration needs to be updated.

    step 1: you'll need to set up a new integration for your chat room via the slack web ui. you'll get a url hook as a result, which starts with https://hooks.slack.com/services/.

    step 2: you'll need a shell script that will parse the alarms and send them to slack. i save this to /usr/local/bin/slack.sh. you're welcome to put it wherever, as long as the icinga user has execute access to it. this is heavily based off of this script, just heavily modified and updated to work with slack's webhooks and using icinga instead of nagios.

    #!/bin/bash
    
    WEBHOST_ICINGA="icinga.yourdomain.com"
    SLACK_TEAM="yourslackteam"
    SLACK_CHANNEL="#yourchannel"
    SLACK_BOTNAME="icinga-bot"
    WEBHOOK_URL="https://hooks.slack.com/services/your/hook/url"
    
    if [ "$ICINGA_SERVICESTATE" = "OK" ]
    then
        ICON_EMOJI=":thumbsup:"
    elif [ "$ICINGA_SERVICESTATE" = "WARNING" ]
    then
        ICON_EMOJI=":loudspeaker:"
    elif [ "$ICINGA_SERVICESTATE" = "CRITICAL" ]
    then
        ICON_EMOJI=":broken_heart:"
    elif [ "$ICINGA_SERVICESTATE" = "UNKNOWN" ]
    then
        ICON_EMOJI=":troll:"
    else
        ICON_EMOJI=":octocat:"
    fi
    
    curl -X POST --data "payload={\"channel\": \"${SLACK_CHANNEL}\", \"username\": \"${SLACK_USERNAME}\", \"icon_emoji\": \":vertical_traffic_light:\", \"text\": \"${ICON_EMOJI} host: $ICINGA_HOSTNAME\nservice: $ICINGA_SERVICEDISPLAYNAME\nstate: $ICINGA_SERVICESTATE\nmessage: $ICINGA_SERVICEOUTPUT\nrunbook: $ICINGA_SERVICENOTESURL\nlink: \"}" ${WEBHOOK_URL}

    step 3: modify your icinga instance to use your new script. this is going in the commands.cfg file but really it can go in any config file under objects.

        # 'notify-service-by-slack' command definition
        define command {
               command_name     notify-service-by-slack
               command_line      /usr/local/bin/slack.sh
               }
    
        # 'notify-host-by-slack' command definition
        define command {
               command_name     notify-host-by-slack
               command_line      /usr/local/bin/slack.sh
               }

    we also need to modify our contact so that it also sends the message over slack. find your contact that is currently getting alarms, and just add our new commands in separated by a comma.

    service_notification_commands   notify-by-email,notify-service-by-slack
    host_notification_commands      host-notify-by-email,notify-host-by-slack

    step 4: reload icinga.

    step 5 (optional): customize.

    the curl inside the script is utilizing icinga's macros to turn the variables into actual values. you can view the whole list here. please note that the format in the script prefixes ICINGA_ before each variable. i'm unsure why this is needed, the macros page doesn't talk about it.

    hopefully there is another admin out that that will find this useful.

    Comments

  2. batch rename files in windows with powershell

    i had a bunch of files in a folder, and i needed to mass-rename them by replacing things. windows doesn't have a way of doing this from explorer (still! even in windows 10!). normally i would open a cygwin shell and do this via bash, but cygwin doesn't mount your network drives (where these files lived).

    so, powershell it is.

    Dir | Rename-Item –NewName { $_.name –replace "hate","love" }

    this replaces all instances of hate with love in the filename. the syntax is actually quite easy to understand, though i loathe the idea of using Title Case for commands. it just looks... ugly.

    when i finally stop spending money on other important things (like a new car) i'll buckle down and build a hackintosh and leave windows solely for the htpc. until then, it'll be my daily driver at home.

    Comments

  3. moving files into subdirectories based off the first letter.

    when building an rpm-based distribution, the standard is to put packages in subdirectories based off their name. unfortunately, the distribution gods did not bless us with a script to automate the process.

    so, i wrote one.

    for i in ./*; do FOLDER=$(echo $i | cut -c 3-3 | tr '[a-z]' '[A-Z]'); mv $i ./$FOLDER/ ; done

    Comments

  4. i'm an extremely lazy admin.

    so, i have this list of 7zipped files in a directory, right?

    i want to loop through and unzip them all into their own folders. this echo works.

    for z in *.7z ; do echo "7z x \"$z\" -o\"`basename "$z" .7z`\"" ; done
    7z x "my zip.7z" -o"my zip"
    7z x "my zip 2.7z" -o"my zip 2"
    7z x "my zip 3.7z" -o"my zip 3"
    

    but when i try it without, bash likes to toss some errors my way.

    `for z in *.7z ; do "7z x \"$z\" -o\"`basename "$z" .7z`\" ; done`       
    bash: 7z x "my zip.7z" -o"my zip": command not found

    so instead of trying to dig further into the problem, i copied the outputted echo into my buffer, ran screen, pasted, and detached.

    the neckbeard in me wants to find a proper way of doing this; the lazy coder in me is satisfied with having a functional answer.

    Comments

  5. google domains

    [whois.publicinterestregistry.net] Domain Name:TEKNOLUST.ORG
    Domain ID: D137789443-LROR
    Creation Date: 2007-01-20T18:51:15Z
    Updated Date: 2014-09-08T23:41:02Z
    Registry Expiry Date: 2017-01-20T18:51:15Z
    Sponsoring Registrar:Google Inc. (R1356-LROR)
    Sponsoring Registrar IANA ID: 895

    i got my invite to google domains today. so far, i'm a fan of what i see. the unexpected surprise of google domains is their dns management; it's superb. it supports wildcards for subdomains, synthetic records, and was able to automatically import my existing dns settings. this saves me on using afraid.org for my nameservers. while they've treated me well for nearly a decade, they've had one too many outages to my liking.

    google dns screenshot

    private domain registration is free. huge plus.

    i had to pay $12 to transfer the domain, but i get another year of registration out of it (i was going to pay again anyway). the list of tlds available is fairly lacking, so if you're using anything but the typical ones (and strangely, .tips is available amongst the new tlds), you're outta luck registering of transferring. i have a single .ws domain which surprisingly isn't supported.

    as an aside, the amount of email noise generated from transferring a domain is ridiculous. i hate email. each registrar essentially talking back and forth to each other with you standing in the middle unable to move out of the way of the conversation.

    but i mean, it's just a registrar. it doesn't give you super powers or make you rank better in search. it has a simple, clean interface that is just utterly refreshing after using godaddy for so long.

    Comments