Wednesday, February 22, 2012

Difficulties with Google Gadget in WordPress

I had a hard time trying to put my little flickr-show Google Gadget into a WordPress page -- Various versions of the gadget has been used in Google Sites and Blogger pages (also on the sidebar) successfully.

This gadget is very much a proof of concept: The Gadget concept is Google's way for developers to write small apps in XML and JavaScript that could be placed in all kinds of web pages and the Google Desktop. It's not a novel concept but Google seems to be the most open among the companies that have something like it. Google Gadget is simple conceptually: You write an XML module that specifies a number of things, among that relevant to interfacing with the users are (1) a section for options, (2) content area which functions as an HTML/DOM container, (3) JavaScripts that work in the content area and (4) optional message files in XML for multiple language support.

One issue I take with Google's handling of gadgets is inconsistency: The same gadget behaves differently in Google Sites than in a non-Google website where you have to use Google's gadget creator tool to turn the XML modules into an HTML for rendering by user's browsers. Little differences can be very annoying. For example, the gadget creator tool generates three div containers around the iframe with white background color for no apparent reason. I mean, I can understand that Google wants to put their logo on rendered gadgets, but why this obnoxious white background?

Blogger allows gadgets in the sidebar directly. But if you want to put one in your blog entry contents, you have to run it through the gadget creator. Now, on to what I think is a bug somewhere in the Google code cloud. The code the creator tool generated calling Flickr's API function to search for photos returns an empty list in a WordPress page while it works in a Blogger page -- I have later learned that this could be caused by the chaotic use of jQuery in WordPress and many of its plugins, but this seems to be a problem of a different kind as the call does go out through Google's gadgets.io.makeRequest() proxy function and return with results.


To avoid using the Google gadget creator tool, I made changes to make the flickr-show.js module work with or without the Google Gadget API.


On the WordPress side, we observed a situation in which multiple instances of jQuery gets loaded. Which caused chaos for jQuery UI: UI widget functions would randomly disappear from the jQuery namespace. WordPress seems to need a JavaScript library manager badly -- something like the Drupal JavaScript Libraries Manager.

Tuesday, February 21, 2012

An InterMapper Probe in Python

InterMapper ships with Python -- the recent releases come with Python 2.7, making extending it using Python a natural choice.

So when a colleague diagnosed a problem between Cisco ACE and some application servers it load-balances for, I thought about turning his curl script into a probe. Previously I tried to put curl on the Windows 2008 server where our InterMapper software runs, but I didn't get far with that effort. I turned to Python since then when I need to do anything with InterMapper, like writing notifiers and probes.

My notifier and probe code are available on Google Code. My first probe is one that talks to the Cisco xml_agent process, which seems to be supported in more and more Cisco boxes. The probe itself is in the xmlprobe.xml file -- Simple installation instructions are found in there. It connects to the agent on a Cisco box via HTTPS and runs a command configurable either in a configuration file or via InterMapper's "set probe" dialog.

Lessons learned in writing this simple probe: I really hope InterMapper has more documentation about the details of the probe syntaxes. For example, in the section, the arg value doesn't seem to require quotes around it, which leaves the double-quote to be used for quoting individual command line parameters. Also, Windows handles quoted command line parameters differently than Linux -- That caused my much grief as the command used in this case is "show xlate global %(vip)s | count" and the vertical bar caused error when InterMapper runs the probe although it runs fine manually under Cygwin. After searching around in the InterMapper support forums, I happened upon an earlier Q&A topic and found out how to turn on the detailed logging for troubleshooting a command line probe, which revealed the error that I did not see in my manual command line tests.

This probe still looks messy: The JSON configuration data has to be edited manually. It seems that a web-based front-end tool would be helpful. It seems that InterMapper could extend its HTTP API so that the remote access client could be extended through server side plug-ins.

Thursday, February 9, 2012

Working with Cisco LMS Database in Python

Cisco has published its CiscoWorks LAN Management Solution (LMS) database schema (4.2) since version 3.2. JDBC and ODBC are supported methods for accessing data LMS has collected. Setting up ODBC is a bit involved especially when I don't have the privilege to upgrade OS in a box. I don't particularly like Java either. So I thought about getting access to the data locally and possibly provide that data remotely through a web-based interface using an easier-to-use Python-based framework, maybe something like web2py.

So I installed Jython on the Windows Server 2008 box which runs my LMS 4.1 installation, copied down some sample Java code from Cisco and translated that into Python. After a few tries to get Jython to find the right Java class path, it actually worked.

So here is the code (of course, userid and password have to be filled in) that prints a list of devices in the database:


#!/usr/bin/env jython
##
##      Requires this: export CLASSPATH='E:\CSCOpx\lib\classpath'
##


import time
import java.sql


import com.sybase.jdbc2.jdbc.SybDriver


conn = java.sql.DriverManager.getConnection("jdbc:sybase:Tds:localhost:43441?SERVICENAME=cmfDb", userid, password)
print('[%s] INFO: Connection successful...' % time.strftime("%c"))
stmt = conn.createStatement()


query = "SELECT Device_Id, Device_Display_Name, Management_IPAddress FROM Network_Devices"
rs = stmt.executeQuery(query)


cnt = 0
while rs.next():
        cnt += 1
        print("%d. Device Id: %s" % (cnt, rs.getString("Device_Id")))
        print("  Display name: %s" % rs.getString("Device_Display_Name"))
        print("  Management IP address: %s" % rs.getString("Management_IPAddress"))

Friday, February 3, 2012

Obscure Problem with LMS 4.1

Finally got around to put Cisco Prime LMS 4.1 (They seem to be retiring the CiscoWorks brand.) on a Windows 2008 server -- I want to go the appliance route but more work is needed to get a VM in the enterprise environment for that.

First impression: LMS 4.1 looks very different from 3.2.1 on the web-based GUI. Cisco did put effort into modernizing the web-based interface and rearranging components to suite a network manager's work flow rather than around the various pieces that Cisco acquired to make up the LMS bundle. However, one may learn quickly the difference is much less profound under the hood.

Right off the bat, I hit a small snag.

After installation, I enabled HTTPS in Admin by going into Admin » Getting Started » Other System Settings » System Settings » Browser-Server Security Mode, selected Enable HTTPS and applied that setting.

After that, a user browser visiting the LMS server using HTTPS://server-name is redirected to http://server-name:1741/... after login, which produced a 403 (Forbidden) error.

TAC was not much help in this case. After poking my way around the server and the GUI, I think I have fixed the problem:

Go to Admin » Trust Management » Local Server » Browser-Server Security Mode Setup, select Change Setting To: Enable and apply.

It seems to me that both Browser-Server Security Mode from Getting Started and Browser-Server Security Mode Setup in Trust Management should mean exactly the same thing. But apparently they do not do the same thing.