My very own hackergotchi head

Last week I found this Avatar while browsing the Ubuntu community forums. I really like the style and decided to make one myself which should also look kinda like me.

The result is my own personal “hand drawed” hackergotchi. I used a picture taken at work and Inkscape to do the magic. It might look even better if I applied an uneven stroke like the one from the Ubuntu forums. Right now Inkscape does the stroke which is kinda dull. But it will suffice for now.

Gtk.TreeView right click part 2

While on my winter vacation I played around with the Gtk.TreeView and the right click challanges. I found a way to extract the row which is clicked on and the data within. The following example shows how (it builds upon my last Gtk.TreeView right click example:

public class TreeViewExample {
    public static void Main ()
    {
        Gtk.Application.Init ();
        new TreeViewExample ();
        Gtk.Application.Run ();
    }

    public TreeViewExample ()
    {
        Gtk.Window window = new Gtk.Window ("TreeView Example");
        window.SetSizeRequest (500,200);

        MusicTreeView tree = new MusicTreeView ();
        window.Add (tree);
        window.ShowAll ();
    }
}

// Creating a new class MusicTreeView which is derived from the TreeView class
public class MusicTreeView : Gtk.TreeView {

        private Gtk.ListStore musicListStore;

        public MusicTreeView ()
        {
                musicListStore = new Gtk.ListStore (typeof (string), typeof (string));

                this.AppendColumn ("Artist", new Gtk.CellRendererText (), "text", 0);
                this.AppendColumn ("Title", new Gtk.CellRendererText (), "text", 1);

                musicListStore.AppendValues ("Garbage", "Dog New Tricks");
                musicListStore.AppendValues ("The Chemical Brothers", "Galvanize");
                this.Model = musicListStore;
        }

        // The TreeView has a build in function which is called upon a OnButtonPressEvent
        // We override the function to capture right clicks with the mouse
        protected override bool OnButtonPressEvent (Gdk.EventButton evnt)
        {
                if(evnt.Button == 3) {
                        Gtk.TreePath path = new Gtk.TreePath();
                        // Get TreePath from the xy-coordinates of the mouse from the event
                        // GetPathAtPos is a function from the TreeView class
                        GetPathAtPos (System.Convert.ToInt16 (evnt.X), System.Convert.ToInt16 (evnt.Y), out path);
                        Gtk.TreeIter iter;
                        // Get iter from the path
                        if (this.musicListStore.GetIter (out iter, path)) {
                                // Get artist and title from the iter
                                string artist = (string) this.musicListStore.GetValue (iter, 0);
                                string title = (string) this.musicListStore.GetValue (iter, 1);
                                System.Console.WriteLine ("Artist: " + artist + ", Title: " + title);
                        }
                        return true;
                }
                // Now if we would ever get this far
                // we run the TreeViews OnButtonPressEvent function
                // to make sure everything else works as normal
                return base.OnButtonPressEvent(evnt);
        }
}

Notes I found in Monodoc:

  • TreePath represents a particular node of a TreeView
  • The TreeIter is the primary structure for accessing a tree row.

Whatever that means :)

XSLT: Search replace attribute values

Yesterday I needed an xsl transformation which could replace a specific attribute value in a xml file and keep the rest intact. The following code is put together by pieces I found around the net (copy-paste FTW :) ):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:param name="attribute"/>
    <xsl:param name="oldvalue"/>
    <xsl:param name="newvalue"/>

    <xsl:template match="node()|@*">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
    </xsl:template>

    <!-- This is a generic search replace of attribute values -->
    <xsl:template match="@*" priority="10">
        <xsl:attribute name="{name()}">
            <xsl:choose>
                <xsl:when test="(name()=$attribute) and (. = $oldvalue)"><xsl:value-of select="$newvalue"/></xsl:when>
                <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
            </xsl:choose>
        </xsl:attribute>
    </xsl:template>
</xsl:stylesheet>

Lets say that the above code is saved in a file called attribute_replace.xslt. Now with xsltproc you would be able to replace the vaule 5011 with 5015 in all attributes called port:

xsltproc --stringparam attribute port --stringparam oldvalue 5011 --stringparam newvalue 5015 attribute_replace.xslt server_config.xml > new_server_config.xml

I used this to manupulate with some JBoss configuration files.

Heartbeat starting my resources twice... why?

While working on implementing failover for a JBoss application in heartbeat I had it sometimes fail miserably. After examining the logs files for a while I noticed that it tried to start my service twice.. why?

This was due to multiple errors from my side:

  1. I hadn’t implemented the status call for my heartbeat resource script
  2. My script didn’t return true when asked to start and it was already started.

According to LSB standard your start / stop scripts should return true even though your service is already started.

Note to self: Learn to read the documentation and not just assume you know how it works (especially not with failover clusters… they are meant to have uptime you know.

Good readings about heartbeat and the resouces scripts.

HTTP POST requests from command line with curl

One of our customers have a JBoss application which they wanted to monitor with a script (in the long run Heartbeat2). By making a specific HTTP POST request to which the answer is known, it is possible to check if the server is running as expected. The HTTP POST request consist of a header and a body. The header is automaticaly generate from the parameters you provide curl and the body is provided in the --data parameter.

The following is an example close to what I used, and beneath a description of the parameters used parameters:

curl --insecure \
     --user monitor_user:heykcnhre \
     --header extra-header:12345678 \
     --include \
     --data '

    7
    get_email
' https://localhost:5011/check
  • --insecure ignores unverified SSL certificates
  • --user authentication information need to access the server and make the http request in the first place.
  • --header provides extra header information. You can add as many of theese as you need.
  • --include includes the header in the response (not only the body)

Curl takes many different parameters use man curl for more info.