Steve Jobs 1955 – 2011

Steve Jobs 1955 - 2011
Earlier today, Steve Jobs passed away at only 56 years old. He’s had an incredible impact on the tech industry and touched millions of people. To me, his keynotes (“SteveNotes”) and his incredible attention to detail in all of Apple’s designs have been a huge inspiration.

XKCD paid him a fitting tribute:

Eternal Flame

“There’s always the hope that if you sit and watch for long enough,
the beachball will vanish and the thing it interrupted will return.”

Twagios 2.0 – Nagios notifications revisited

In a previous blog post, I described how to use Twitter for Nagios notifications – dubbing it “Twagios”.

A couple of months later, Twitter stopped supporting basic authentication (username/password). This meant that the old (simple) way of sending notifications stopped working. In this post, I’ll explain how I replaced the old Twagios with a new script – “Twagios 2.0” ;-)

First of all, a big thank you to Jeff Miller for writing this excellent post on using the Python tweepy library to create a simple command line client. I simply followed Jeff’s instructions…

  1. Install the tweepy library
  2. Create a new OAuth registration at http://twitter.com/oauth_clients
  3. Create the new “Twagios 2.0” client
  4. Configure Nagios notifications

Install the tweepy library

I’m on CentOS 6.0. Assuming that you already have Python installed, the easiest way to get tweepy is through pip, the Python package manager:

  yum install python-pip
  pip-python install tweepy

Note: why name the package python-pip, and the binary pip-python? How intuitive ;-)

Create a new OAuth registration

I am assuming that you already created a separate Twitter account for sending out Nagios notifications – if not, read my old blog post. The next steps were taken from Jeff Miller’s blog:

Go to http://twitter.com/oauth_clients and log in with your “Twitter Bot” account. Register a nice name for your new script as a “client” with “read & write” permissions. Twitter should issue you with a “Consumer Key” and “Consumer Secret” for your new client.

Authorize access to your “Twitter Bot” account by replacing the CUSTOMER_KEY and CUSTOMER_SECRET values in the following temporary script:

  #!/usr/bin/env python

  import tweepy

  CONSUMER_KEY = 'paste your Consumer Key here'
  CONSUMER_SECRET = 'paste your Consumer Secret here'

  auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
  auth_url = auth.get_authorization_url()
  print 'Please authorize: ' + auth_url
  verifier = raw_input('PIN: ').strip()
  auth.get_access_token(verifier)
  print "ACCESS_KEY = '%s'" % auth.access_token.key
  print "ACCESS_SECRET = '%s'" % auth.access_token.secret

Run the script, open the “Please authorize” URL in your browser and confirm authorization for your “Twitter Bot” account. Twitter should now give you a PIN number. Enter this PIN number and the script should display an ACCESS_KEY and ACCESS_SECRET. We now have all the information successfully authenticate the new client with Twitter.

Create your new “Twagios 2.0” client

Create the actual “Twagios 2.0” script; replace the CONSUMER_KEY, CONSUMER_SECRET, ACCESS_KEY and ACCESS_SECRET with the proper values:

  #!/usr/bin/env python
  #
  # See: http://talkfast.org/2010/05/31/twitter-from-the-command-line-in-python-using-oauth

  import sys
  import tweepy

  CONSUMER_KEY = 'paste your Consumer Key here'
  CONSUMER_SECRET = 'paste your Consumer Secret here'
  ACCESS_KEY = 'paste your Access Key here'
  ACCESS_SECRET = 'paste your Access Secret here'

  auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
  auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
  api = tweepy.API(auth)
  api.update_status(sys.argv[1])

Done! Send your first tweet:

  chmod 755 twagios
  ./twagios "Hello World"

Configure Nagios

The notification commands describedin my old post should be changed as follows:

  ### Twitter ###

  define command{
        command_name    host-notify-by-twitter
        command_line    /usr/local/bin/twagios "@MyTwitterAccount $HOSTALIAS$ is $HOSTSTATE$. $HOSTOUTPUT$. Time: $SHORTDATETIME$"
  }

  define command{
        command_name    notify-by-twitter
        command_line    /usr/local/bin/twagios "@MyTwitterAccount $SERVICEDESC$ @ $HOSTNAME$ is $SERVICESTATE$. $SERVICEOUTPUT$. Time: $SHORTDATETIME$"
  }

Note: Replace “@MyTwitterAccount” with your actual Twitter account so your Twitter Bot account can send you @mentions.

You could even have it send DM’s by prefixing the message with “d “, for example:

  /usr/local/bin/twagios "d @MyTwitterAccount $HOSTALIAS$ is $HOSTSTATE$. $HOSTOUTPUT$. Time: $SHORTDATETIME$"

Update 2011.12.05 – message length check

As suggested by @erik_mol on Twitter, the above script lacks a check for message length (140 characters max.):

Twagios script needs minor tweak; s = sys.argv[1] api.update_status(s[0:140]). Saves other readers headache, thanks

As message length is indeed important, I have also added some sample substitutions (“WARNING” becomes “WARN” and so on), reducing message length where possible.

  #!/usr/bin/env python
  #
  # See: http://talkfast.org/2010/05/31/twitter-from-the-command-line-in-python-using-oauth

  import sys
  import tweepy
  import string

  CONSUMER_KEY = 'paste your Consumer Key here'
  CONSUMER_SECRET = 'paste your Consumer Secret here'
  ACCESS_KEY = 'paste your Access Key here'
  ACCESS_SECRET = 'paste your Access Secret here'

  auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
  auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
  api = tweepy.API(auth)

  # Process the commandline argument, replace words etc. to shorten the message
  s = sys.argv[1]
  s = string.replace(s,"WARNING","WARN")
  s = string.replace(s,"PROBLEM","PROB")
  s = string.replace(s,"CRITICAL","CRIT")

  # Send the message, 140 characters max.
  api.update_status(s[0:140])

Enjoy the script – happy Sinterklaas everyone ;-)

Tip: Importing multiple CentOS Linux DVDs into Cobbler

Linux distributions are getting larger and larger; CentOS 6.0 64-bit won’t fit on a single DVD anymore. A Cobbler-based provisioning server will normally import only one DVD. So, how do you get around this?

  1. Import the first DVD as usual
  2. Manually add content from the second DVD

Import the first DVD (ISO image):

  mkdir /mnt/dvd1; mount -o ro,loop /tmp/CentOS-6.0-x86_64-bin-DVD1.iso /mnt/dvd1

  DISTRO=centos60-x86_64
  cobbler import --name=${DISTRO} --path=/mnt/dvd1

Watch the output from Cobbler closely – it will basically tell show you the commands you need to import the second DVD ;-)

Import the second DVD (ISO image):

  mkdir /mnt/dvd2; mount -o ro,loop /tmp/CentOS-6.0-x86_64-bin-DVD2.iso /mnt/dvd2

  rsync -a  '/mnt/dvd2/' /var/www/cobbler/ks_mirror/${DISTRO} --exclude-from=/etc/cobbler/rsync.exclude --progress
  COMPSXML=$(ls /var/www/cobbler/ks_mirror/${DISTRO}/repodata/*comps*.xml)
  createrepo -c cache -s sha --update --groupfile ${COMPSXML} /var/www/cobbler/ks_mirror/${DISTRO}

Done! You have now added the contents of the second DVD to your existing “ks_mirror” directory and updated the Yum repodata.

Update 2011.08

  • FIXED: Forgot the trailing / on the DVD2 mount point '/mnt/dvd2/'. Otherwise, the rsync command will create a 'dvd2' subdirectory.

JeeNode, JeeLink and the Arduino IDE

The Arduino IDE is used to program and debug your Arduino-compatible boards. JeeLabs has a variety of Arduino-like boards. I use the following settings in the Arduino IDE:

On Mac OS X, the Serial port (Tools/Serial Port) should be set to a device named /dev/tty.usbserial-XXXXXXXX. The speed should be set at 57600 bps.

JeeLabs device Arduino IDE: Tools/Board
JeeLink v3 Arduino Uno
JeeNode v6 Arduino Duemilanove or Nano w/ ATmega328

TIP: If you have more than one board, multiple serial port devices will exist. You can easily find out the right one by checking the available entries first (in Tools/Serial Port), then plugging in the board, then checking again.

ZeroPlus LAP-C 16032 Logic Analyser

When working with digital electronics, a Logic Analyser can come in handy to display and decode all these signals. I recently bought an entry-level Logic Analyser with 16 channels – more than enough for testing and debugging my future JeeNode projects. It offers a large selection of downloadable Protocol Analysers. These software plugins are installed on your computer, and aid in interpreting bus signals like RS232, I2C, CAN and SMI.

Software

The Zeroplus LAP-C 16032 comes with Windows-software. There is an Open Source project called “sigrok” that offers alternative software for the Zeroplus Logic Cube series of analysers. They also support Protocol Analysers in the form of Python plugins.

Hardware

Apparently the Zeroplus LAP-C series can be modified to unlock new features, like sampling speed and memory depth.

References