Monday, April 13, 2009

How bloody illogical is .NET anyway

What is it with Microsoft, .NET and their inability to make any form of sense.

In what is now a completely aborted attempt to write a traffic grapher in VB.NET, I have discovered some of the most insane, illogical and impossible coding pitfalls and traps ever.

Using a DataTable from an event triggered by WinPCap's capture thread, I get random, and I mean random, null exceptions when attempting to call DataTable's NewRow(). Google is surprisingly unhelpful with this one, talking about uninitialized objects and so forth. Finally I stumble across an idea that it might be a race condition.

So I thread-lock the bastard. And what do you know, SyncLock generates an exception saying it cannot obtain a lock on a null object. Now what? I wrap the code in an If DataTable IsNot Nothing block, which stops the exceptions. Except now I'm losing packets when I capture, compared to Wireshark running with the same parameters. Gah.

After a while, I try to change the capture mode from x packets to continuous. Three ways of doing it according to the documentation.

I can Capture(-1) packets which then runs an infinite capture. Which is a blocking call and can't be stopped short of terminating the program. That ain't fun. Please do not recommend that in documentation.

Secondly, I can use a WinPCap function called StartCapture() that, it promises, will capture until StopCapture() is called. Fine. Works. Program is responsive. Except no packets are being logged. Quick check shows the ***king DataTable is always Nothing when the event handler is fired. Seems like a threading issue. Too much effort to figure this one out.

Lastly, I can eschew the event handler method and go directly to the GetNextPacket() function which returns a packet from the device, or Nothing if none appear before the timeout. Couple of mods to the event handler delegate and it becomes a function I can call. Works nicely. Still dropping packets, but not as many.

But, horror of horrors, I've hacked it together in a Do While Loop structure which spins in a circle waiting for a locking variable to be unset. Thing is, the handler for the Stop button is being blocked by the Do While. Or the actual UI is being blocked. I know this is evil, but it was intended as an intermediate step just to get the GetNextPacket() bit working.

So dig out some timer code and implement a Timer.Elapsed handler that loops the interface until a Nothing is returned, sleeps 100ms to allow UI bits, and goes on. Thing is, System.Timers.Timer is threaded and now I'm getting some cross-threading delegation complaints and I'm supposed to implement Invoke calls to reach functions on the other thread. Fine. Right up until I find out there is no Invoke function on a DataTable object. On the holder form and the DataGrid it's bound to, yeah, but not on the bloody DataTable.

Google says use a System.Windows.Forms.Timer to keep it in the main thread. So then the UI updates as hundreds of packets are added to the DataTable now make hitting the Stop button nigh on a miracle.

So I've trashed the idea and am looking at C and GTK on Windows for this bloody thing.

We won the cricket - Again

So, once again it sucks to be the Aussies.

After winning the ODI series in Australia, then losing the Test series in South Africa, our boys have hammered the Aussies in both the T20 series and now the ODI series.

While we ain't king of the Test Match rankings, we have certainly cemented our position at the top of the logs for One Day Internationals. Well done Graeme Smith and the boys.

And he ain't a relative.

Roll on the IPL. That's going to be fun, fun, fun.

Monday, January 26, 2009

We won the cricket

Yaah boo, sucks to be you, Aussies.

And with an 8 wicket, 11.3 over drubbing of Australia in Adelaide, on Australia Day, South Africa takes home both the Test and ODI series trophies.

I wonder if they will allow us to play in the Ashes?

Friday, January 23, 2009

SQL 2005, How Do I Hate Thee

Let me count the ways.

Not being able to get to saved packages once you've saved them to the database.

A convoluted, ridiculous security architecture that doesn't allow you to use internal SQL accounts to run certain types of jobs without jumping through more hoops than a show dog.

Database structure exports that don't export triggers without specialized code.

A backup system that looks at last-modified dates instead of created dates to decide if it should delete backups older than a certain time.

Backup maintenance plans that do not include log backups by default.

SQL Server 2005 has to be one of the most unmanagable databases I've ever worked with.

Friday, January 02, 2009

This is embarrassing

A whole year since I last posted. That is scary. Eerily reminiscent of most blogs, but still scary.

So, what happened? Too much work, too many people and not enough fun was had. Must correct that this year.

Wednesday, January 16, 2008

Working with OpenNMS

Been driving very hard to customize the OpenNMS installation at the university the last week. The biggest issues have revolved around the polling options, both the SNMP and the new HTTP poller system that has been introduced into the dev release.

For some annoying reason, to do with OID's and other arcane bits of SNMP, several of my nodes have decided to stop polling network adapters and to not pick them up with rescans either. Some nodes finally came right with a delete of the interfaces associated with the node, a manual insert into the ipinterface table and a rescan. Some are still giving major problems. But I'll sort those out, eventually.

Of a more interesting, and incredibly frustrating, ilk is the new HTTP poller that's in the 1.3 dev release. This beauty of a system allows OpenNMS to fetch a web page from a server, find specific blocks of text in the HTML of the page and pull numbers out into an RRD database. Very useful for those odd polling items that just don't pitch up in Microsoft's SNMP system. Only problem is that the tutorial on OpenNMS's site isn't quite right.

I've been working on getting Exchange stats out for a while now and found a really nice mechanism in the HTTP poller for that. Take a ASP.NET page that accesses the Performance Counter object for Exchange processes, extract that counter data and shove it into the RRD database. Voila, we have stats that Microsoft's SNMP hasn't returned since Exchange 2000 and that SNMP Informant wants $7500 odd to return for me. I'll publish source code soon for this.

Alongside all this are the custom graphs I've been working with. I've drawn up a large set for AIX CPU stats, Exchange and others. I'll be posting these soon as well for your enjoyment. While I'm at it, can anyone tell me whether I can draw RRD graphs with optional .rrd files.

AIX currently produces a separate SNMP entry, and therefore file, for each virtual CPU that it sees. Now because our LPARs are structured differently, one server has 6 CPUs, one 4 CPUs and two have 2 CPUs. If I define a summary graph for 6 CPUs, it draws for one server, but not the rest. Another graph for 4 CPUs appears both for the 4 CPU server and for the first 4 CPUs of the 6 CPU server.

If I can specify that each .rrd file is optional in the command line, then I can get to one defined graph for any AIX node. I can't find instructions to do this anywhere in RRDTools info docs or on Google. 10000 brownie points to someone with an answer.