Thursday, January 07, 2010

Some Nagios Notes for HTTP Monitoring

I needed to monitor some non-standard HTTP  ports with Nagios.  Installation went well, but it took a little fooling around to get the HTTP monitoring the way that I wanted.  [N. B. After writing this, I realized later that the default settings could probably do what I wanted.  But here it is anyway.]

First, make sure your check_http command is working correctly.  It is in $NAGIOS_HOME/plugins/check_http.  Use --help to see your options.  You'll note that there are several, but the actual command that Nagios runs is defined in the file commands.cfg.  The default is

# 'check_http' command definition
define command{
        command_name    check_http
        command_line    $USER1$/check_http -I $HOSTADDRESS$ $ARG1$
        }

I changed the command_line to

        command_line    $USER1$/check_http -I $ARG1$ -p $ARG2$

You could of course add additional options supported by check_http.

Next, you need to add hosts to be monitored.  I just appended these to localhost.cfg.  This is an example for monitoring http://my.machine.indiana.edu:9999 (with IP addres 123.456.789).

define host{

        use             linux-server            ; Name of host template to use

        host_name       my-machine       ; The name we're giving to this host

        alias           CICC Tomcat     ; A longer name associated with the host

        address         123.456.789           ; IP address of the host

        hostgroups      linux-servers           ; Host groups this host is associated with

        }


define service{
        use             local-service         ; Name of service template to use

        host_name       my-machine

        service_description     HTTP

        check_command   check_http!my.machine.indiana.edu!9999
        notifications_enabled           0

        }

That's it.  Maybe there is a better way to do this but I could not find it easily.

Monday, January 04, 2010

Quick Guide to Using Open Social's Activity API with Google Friend Connect

As I've discussed in some previous posts, Google Friend Connect gives you a simple way to access Open Social applications.  The JavaScript API is pretty simple and is mainly useful for logging in, setting up small social networks, and rendering social gadgets.  You can use  the JavaScript API to decorate HTML with various social mini-gadgets for tagging, rating, commenting, and so on.

In this post, we'll look at how to directly call the Open Social API without going through a pre-existing gadget.  Our motivation is the Open Social Activity API.  Familiar social networking sites like Facebook and Twitter have "activity streams" in which each user posts status updates. These can also be automatically generated side effects (such as bookmarking a site with Del.icio.us's Twitter interface, for example).

An Open Social Activity API example using Google Gadgets is here: http://code.google.com/apis/opensocial/docs/0.8/devguide.html#Activities.   In addition to being an HTML gadget, this relies on the Gadget API (see the call to gadgets.util.registerOnLoadHandler(startActivity) near the bottom). To do the same thing with Google Friend Connect, we need to take the following steps:
  1. Load the FriendConnect JavaScript libraries with google.load.
  2. Use the FriendConnect libraries to initialize an OpenSocial API call.
  3. Pass in a callback function (startActivity() in our example) that the server side (at Google HQ, presumably) will invoke. 
  4. Implement the callback function using the OpenSocial Activity API. 
The code for doing this is below, with comments.

<html>
<!--Shows how to use the Open Social activity API with Google Friend Connect -->
<body>
  <div id="content_div"></div>
  <!-- Initialize the Google Friend Connect OpenSocial API. -->
  <!-- Load the Google AJAX API Loader -->
  <script type="text/javascript" src="http://www.google.com/jsapi"></script>
 
  <!-- Load the Google Friend Connect javascript library. -->
  <script type="text/javascript">
    google.load('friendconnect', '0.8');
  </script>
 
  <script type="text/javascript">
          /* This will dynamically change the content to the new activity */
     var div=document.getElementById("content_div");

     /*No caching for development. */

     google.friendconnect.container.setNoCache(1);

     /* Use this to invoke Open Social methods */
     google.friendconnect.container.initOpenSocialApi({
    site: '##########################',   /* Replace this with your GFC ID */
    onload: function(securityToken) { startActivity(); }
     });
  /* This is a callback invoked when we initial the Open Social libraries. It has a callback method of its own, called callback()  */

  function postActivity(text) { 
    var params = {}; 
    params[opensocial.Activity.Field.TITLE] = text;
    var activity = opensocial.newActivity(params);
     
    opensocial.requestCreateActivity(activity, opensocial.CreateActivityPriority.HIGH, callback);

    div.innerHTML = "Activity title is: " + activity.getField(opensocial.Activity.Field.TITLE);
  };       
 
  /**
  * Server calls this function to indicate whether the activity post succeeded or failed.
  */
  function callback(status) {
    if (status.hadError())
    {
      alert("Error creating activity.");
    }
    else
    {
      alert("Activity successfully created.");
    }
  };
 
  /**
   * Start the process of posting an activity.
   */
  function startActivity() {
    postActivity("This is a sample activity, created at " + new Date().toString());
  };

  </script>
 
</body>
</html>

To use this, just save it as an HTML file on a Web server registered to Google Friend Connect and load the page.  You will need to change "################" to use your registered site ID.