Extending Mediawiki for all your sysadmin needs

Way back in June of 2008, I mentioned that I had setup an internal wiki (using MediaWiki) here, for my own use, and for anyone else who wanted to use it. At the time, I lamented the fact that I hadn’t figured out how to reliably manipulate the wiki database.

A year and a half later, that’s still the truth, although I did spend four hours this morning working around that particular problem. I woke up a bit after 4am this morning and of all things, that old problem came to mind. I considered it, and I didn’t necessarily want to populate the database, I really just wanted to display non-static information on the individual pages. I thought a little more and decided that there had to be plugins for MediaWiki, and I got up and started working.

Boy was I right. There are a TON of them. Too many, really. Ever walk into a specialty store looking for something, and it’s a place the size of a warehouse full of whatever you’re looking for, and you’re overwhelmed, and can’t pick? Sort of like that.

Not wanting to browse 1500 extensions, I figured that it couldn’t be that difficult to make my own.

Years ago, I used to be a php programmer. Not a good one, to be sure, but I did sling some code. It was just a while back. It turns out that it’s sort of like riding a bike. I found this tutorial, plus some MediaWiki docs, and hammered out some ugly looking code, but gloriously, it worked.

The extension that I wrote allows you to place the following code in your wikipage: <snmp>hostname,OID</snmp> and have the output of snmpwalk inserted into the text of the page. It’s like magic, as far as I’m concerned :-)



<?php
// netSNMP.php
//
// The following source code is to be considered public domain.
// Please use it to build on
//
// Matt Simmons ([email protected])
// 20091223

if ( !defined ( 'MEDIAWIKI' ) ) { 
   echo "This is an extension to mediawiki, and cannot stand alone";
   die(1); 
}

$wgExtensionFunctions[] = "netSNMP"; 

function netSNMP() { 
   global $wgParser; 
   $wgParser->setHook( "snmp", "getNetSNMP" ); 
}

function getNetSNMP( $input ) { 
// process the input and produce the output
   $arrInput = explode(",", $input); 
   $data = retrData($arrInput); 
 
   $return = "\n" . $data . "\n"; 
   return $return; 
} // end renderFile()

function retrData($arrInput) { 
// Retrieves the data and returns  a string
   $community="COMMUNITYSTRING"; 

   $snmpHost = $arrInput[0]; 
   $snmpOID = $arrInput[1]; 

   // snmp_walk defaults to v1 
   $arrSNMPRes = snmp2_walk($snmpHost, $community, $snmpOID); 

   $result = implode($arrSNMPRes, "<br>"); 
 
   return $result; 
} // end function retrData()
?>

Yes, it’s horribly insecure. Yes, anyone editing any page can query your SNMP-enabled devices (as long as the device has COMMUNITYSTRING as the public string), and it will probably kick your dog. But it’s a proof of concept. It works, and it’s not hard to write these extensions.

You just throw the script in $IP/extensions, modify your LocalSettings.php file to include it, and you’re golden. I wish I would have checked into this much sooner, but now that I know, I can start coming up with good things to enable better wiki usage. I hope this helped.

Rack Area Networking? But what if all you’ve got is a rack?

Have you heard of Rack Area Networking? I hadn’t, until last week or so. According to Nigel Poulton, it’s the newest craze sweeping the server rooms of the rich and famous. Or at least the rich and willing to spend money on hardware.

I’m not entirely sure that I’ve nailed it down just yet, but it sounds like the increased virtualization of, well, pretty much everything, from servers (old hat now) to host bus adaptors (HBAs), to the kitchen sink. And according to Nigel’s blog entry, the emphasis is on the cleverness of it all.

Call me old fashioned, but I get sort of a twitch discussing clever like it’s a good thing. Of course, I could be taking the term clever completely out of context. Some of the technology does sound pretty neat, and Nigel has written another entry since the original devoted to I/O Virtualization, and it features some cutting edge graphics. Go check it out, there’s some serious hardware virtualization going on behind those crayon drawings.

I have no doubt that we small infrastructure admins are not going to have to deal with anything like this in the next year. Heck, I know a lot of shops that are just now getting their feet wet with normal server virtualization, and there’s nothing wrong with that at all. It’s a solution that fits a set of problems, and if you’re not updating your current infrastructure, you probably won’t jump out and implement it. But you should keep your eye on it.

And with these new technologies, 2010 should be interesting. Tech seems to have a trickle-down effect, and it’s probably not going to be all that long before some of the software that we run starts to support that, and once that happens, people like Dell and HP are going to start shipping servers with watered down versions of this hardware, and eventually we’ll need to deal with converged adapters, too.

At least, if we want to.