lae's notebook


I've spent the past few weeks working on a decent-sized project called ZMonitor to help at my current job. It is basically a client I developed in Ruby to show the Zabbix dashboard in a terminal, since there wasn't one available previously (other than this perl+curl mashup my workplace was using).

The main application basically calls the API twice through JSON calls to gather all of the information it needs, and then generates an array of strings and prints them at the end. There is an option to hide events that are in maintenance mode, which can help a lot from spamming you with an unusable list.

The acknowledgement function can accept most regular expressions to allow for mass acknowledgement (however, no wildcards since those can be abused too easily).

There are several TODOs for this application already, too, that I might not get to complete anytime soon. The major one is to use ncurses for rendering the dashboard, and quite a bit of functionality will come with that (such as acknowledging from the dashboard, and maybe interactive filtering). Additional functions for showing the history of a server is also planned, and a calibration function to determine time differences between the local computer and Zabbix master.

1.0.9.pre is for the most part very usable now. I personally think some of the code is a bit ugly since I'm not superb at Ruby yet, so all input is welcome. The whole application is also pretty colourful, don't you think?

First Dive Into Lua - A Battery Widget

So, it's come to the point where my laptop has unexpectedly turned off from a dead battery one too many times, so I decided to write a battery widget using Vicious for the window manager I'm using, Awesome. The configuration files are all written in Lua, and honestly I've never touched Lua or felt like programming in it since it looks so...confuzzling.

Nevertheless, I took a look at the Vicious and Naughty libraries, and some Lua documentation to get this up and running:

batmon = awful.widget.progressbar()
batmon_t = awful.tooltip({ objects = { batmon.widget },})
vicious.register(batmon, vicious.widgets.bat, function (widget, args)
	batmon_t:set_text(" State: " .. args[1] .. " | Charge: " .. args[2] .. "% | Remaining: " .. args[3])
	if args[2] <= 5 then
		naughty.notify({ text="Battery is low! " .. args[2] .. " percent remaining." })
	return args[2]
end , 60, "BAT0")

What this basically does is create a progressbar widget with the Awful library, configure its settings, create a tooltip with detailed information, and registers the widget I created with Vicious. The Vicious portion of it uses the battery widget type and sets a timer to update it every 60 seconds, which updates the progressbar percentage and the tooltip. It also checks for a low battery, which for me pops up a little box at the upper right of my screen.

I'm probably not going to be touching Lua for a while again.

DNS Resolution and Site Moves

For now I have * and * currently pointing to the same server and document root. Anyone who's visiting for or some other service I previously had on my other servers should expect to see those come back up in the coming weeks (possibly this weekend) while I spent some time toying around with nginx' configuration.

With that said, some other special surprises may be in store.

Server Switch!

So, yesterday I had my first dedicated server provisioned, and I've been tinkering with it since then, getting it configured as nicely as I can, with LVM and all sorts of funky things.

This site has now moved to the new server~ The domain is still currently pointing to the old server, and the old server is actually proxying requests to the Jekyll daemon on the new server for the time being, until I get the rest all migrated over.

I'm also going to be working on getting a TremZ server online later - was intending to have it up by now but I guess I delayed myself a little with getting the actual dedicated server. Got a good deal though, through Vee from DediDirect!

A Simple Bash Alarm Clock

Someone on IRC linked to a script called DEADLINE, which got me to thinking, a simple alarm clock script should be easy to concoct in bash if that's what the end goal is. I did a quick Google search but didn't find any simple solutions - they were all excessive in some way. So, here I ended up creating a bash one-liner in a few minutes to see it in practice and confirm I wasn't crazy:

sleep $(( $(date --date="7 pm Feb 23, 2012" +%s) - $(date +%s))); echo "It's been a year since you touched this, and the sky is dark! Lalala."

I could easily expand this to request a simple date and play an audio file:

printf "What time are you setting this alarm for? "
read date
echo Okay! Will ring you on $(date --date="$date").
sleep $(( $(date --date="$date" +%s) - $(date +%s) ));
echo Wake up!
while true; do
  /usr/bin/mpg123 ~/alarm.mp3
  sleep 1

This can accept date inputs like "january 1 next year", "tomorrow", "23:00 today" and so forth. In fact, one could expand this script to test for valid dates, or replace the prompt with argument parsing for the same behaviour as "Deadline." I would also probably suggest adding nohup to the script, to relay its execution from the shell and into the background after the date has been inputted.

In fact, I may update this later when I have the time with a more robust (but still short and inexpensive) version.

There are a lot of things you can do with native UNIX utilities, and I'm not quite understanding why they aren't taken more advantage of.