If you followed my wmic post a while back you’ll have seen that wmic outputs a LARGE amount of data seperated by the | character, sort of like a CSV. This quickly becomes unusable as the first line is the column titles of the data and each following line is a result. So I wrote a small, very much ugly and not exactly rock solid, bit of python to dump wmic output into a Dictionary of Lists. What I mean is every column will be a key in the Dictionary and each value is a list of 1 or more values. So for instance a WMI query of HDDs will likely return 2+ (Your C Drive and a CD Drive), but say one for memory will only return one. Anyway this is pretty basic and doesn’t do much more than print the actual dictionary but it might help someone write a Cacti plugin or a Nagios plugin that can pull free disk space for example.

Here it is: pythonwmic (Yes Sorry it’s called .doc but wordpress doesn’t seem to like .py)

To use it just call the script (first modifying the win32User/Password variables) with one argument which is the IP address of the server you want to query. Bear in mind it’s fairly rough but hopefully enough to get you going. It doesn’t work for all WML queries but the Win32_PerfFormattedData_ ones seem to work nicely (Win32_OperatingSystem I’m looking at you inparticular with your extra | characters in the Name column !).

As an example of output I ran against one of my machines querying the Logical Disks:

{‘DiskBytesPersec’: [‘0’, ‘0’, ‘0’, ‘0’], ‘Frequency_Sys100NS’: [‘0’, ‘0’, ‘0’, ‘0’], ‘PercentDiskReadTime’: [‘0’, ‘0’, ‘0’, ‘0’], ‘Timestamp_Object’: [‘0’, ‘0’, ‘0’, ‘0’], ‘AvgDiskBytesPerTransfer’: [‘0’, ‘0’, ‘0’, ‘0’], ‘PercentIdleTime’: [‘100’, ‘100’, ‘100’, ‘100’], ‘AvgDiskBytesPerWrite’: [‘0’, ‘0’, ‘0’, ‘0’], ‘Description’: [‘(null)’, ‘(null)’, ‘(null)’, ‘(null)’], ‘DiskWriteBytesPersec’: [‘0’, ‘0’, ‘0’, ‘0’], ‘Timestamp_Sys100NS’: [‘0’, ‘0’, ‘0’, ‘0’], ‘DiskWritesPersec’: [‘0’, ‘0’, ‘0’, ‘0’], ‘PercentDiskTime’: [‘0’, ‘0’, ‘0’, ‘0’], ‘AvgDiskQueueLength’: [‘0’, ‘0’, ‘0’, ‘0’], ‘AvgDiskBytesPerRead’: [‘0’, ‘0’, ‘0’, ‘0’], ‘AvgDisksecPerRead’: [‘0’, ‘0’, ‘0’, ‘0’], ‘Timestamp_PerfTime’: [‘0’, ‘0’, ‘0’, ‘0’], ‘Name’: [‘C:’, ‘E:’, ‘F:’, ‘_Total’], ‘CurrentDiskQueueLength’: [‘0’, ‘0’, ‘0’, ‘0’], ‘AvgDisksecPerWrite’: [‘0’, ‘0’, ‘0’, ‘0’], ‘DiskReadBytesPersec’: [‘0’, ‘0’, ‘0’, ‘0’], ‘Caption’: [‘(null)’, ‘(null)’, ‘(null)’, ‘(null)’], ‘PercentDiskWriteTime’: [‘0’, ‘0’, ‘0’, ‘0’], ‘Frequency_Object’: [‘0’, ‘0’, ‘0’, ‘0’], ‘Frequency_PerfTime’: [‘0’, ‘0’, ‘0’, ‘0’], ‘SplitIOPerSec’: [‘0’, ‘0’, ‘0’, ‘0’], ‘AvgDiskReadQueueLength’: [‘0’, ‘0’, ‘0’, ‘0’], ‘FreeMegabytes’: [‘54155’, ‘127668’, ‘69809’, ‘251632’], ‘DiskReadsPersec’: [‘0’, ‘0’, ‘0’, ‘0’], ‘AvgDiskWriteQueueLength’: [‘0’, ‘0’, ‘0’, ‘0’], ‘AvgDisksecPerTransfer’: [‘0’, ‘0’, ‘0’, ‘0’], ‘PercentFreeSpace’: [’77’, ’91’, ’99’, ’90’], ‘DiskTransfersPersec’: [‘0’, ‘0’, ‘0’, ‘0’]}

Have fun, and please post comments, corrections or improvements ! I’m sure there’s better/more_pythonistic ways to build the Dictionary and I will at some stage build a better way to output key bits of data rather than just dump the dictionary as is possibly with a Cacti/Nagios plugin to utilise it.

Before I found out about adtool I was managing users using Windows own command line AD tools via the very cool winexe (Thanks to TMM for pointing me to it in the first place). Winexe is a very nice way to either avoid using pstools from another Windows machine or having to install cygwin SSH server, which to be honest is a bit of a pain unless you package it into your system imaging solution and have it on every machine by default. Winexe allows you full access to a terminal on a Windows or allows you to run commands remotely. It’s fairly easy to install (although it’s be nice if someone with better packaging skills than me got it into Ubuntu), the usual configure make dance. I had a bit of trouble with the tarball so I downloaded the latest SVN snapshot which worked perfectly.

Next on my todo list is a small project that I had already built in my last job where we were *stuck* on NT4. And as Samba 4 isn’t out yet it’s relevant to Samba 3 networks to, whereby certain machines can have different registry files applied against them to do things like switch of USB mass storage and all sorts of things you can do with GPOs if you have AD (and make sure OCS Inventory is on there too !). I already built fairly stable system whereby all these things were applied via domain logon scripts, but the horribleness that is scripting on Windows has spurred me on to write something properly in Python that can be run from a Samba PDC/Linux box on an NT4 network to apply all this stuff….

A simple example is:

winexe -U HOME/Administrator%Pass123 // “ipconfig /all”

There’s more on the site but you can just as simply log into the server entirly with:

winexe -U HOME/Administrator%Pass123 // “cmd”

With Samba 4 coming out *soon* it’s almost redundant but what are weekends for ! So hopefully I’ll get this written in a few hours and it’ll spur me on to get into Django and put an interface on it. It’s certinly getting very easy to manage Windows from Linux, fair play to the Samba team and the EU for badgering MS till they got the documents they needed. What OS you use is becoming less and less relevant.

Last week I found a truly excellent tool for adding, modifying and managing user in Active Directory from Linux. It’s in Ubuntu

sudo aptitude install adtool

For a better guide in setting it up Vide has a great one over at his site.

One thing that got me though, you have to make sure your /etc/ldap/ldap.conf file is set up correctly, which should have been obvious but it stumped me for a while (necessary to allow setting passwords etc.)

Make sure you have the following in your config:

BASE    dc=ad-servername,dc=example,dc=com
URI     ldaps://ad-servername.example.com

This allows you to correctly receive the SSL certificate from the server, otherwise you’ll get an error like this:

bind: : Can’t contact LDAP server (-1)

And hey presto you can avoid using MMC to manage users. 🙂 And if you combine it with wmic ….. happy days !

sudo aptitude install wmi-client

Example of usage is;

wmic -U DOMAIN/administrator%password // “Select * from Win32_Service”

Lists all services, the first line it spits back is the fields which you can use this SQL like language  to filter, so to see only the names of the services installed we’d do:

wmic -U DOMAIN/administrator%password // “Select Name from Win32_Service”

Or Name and State:

wmic -U DOMAIN/administrator%password // “Select Name,State from Win32_Service”

Or for just one service in this case the UPS service:

wmic -U DOMAIN/administrator%password // “Select Name,State from Win32_Service where name=’UPS'”

The language for the queries is called WQL and a reference is available here over at MSDN.

Hope this helps, this is only in Hardy as far as I’m aware.

Just a quick post to make public a new library I’ve been working on (based on the initial work of Andre LaBranche). The code is distributed under the LGPL and I hope it proves useful to someone. It was written about a year ago when, to put it plainly, my Python skills where not exactly awesome, so at some stage it’ll be getting a rewrite and tidy up. Anyway to get it head on over to:

Google Code

WARNING: Before doing this bear in mind that if your laptop explodes in a cloud of molten plastic and silicon that I warned you and I take no responsibility… so don’t blame me ! 😉

A Friend of mine was running CentOS on a Thinkpad T43 (this should work on all though) and the fan was running but apparently not enough to stop the laptop dying after a hour or so. Sounds like a hardware issue, but nonetheless here’s a wee hack to get it to run in Maximum Fan Mode and so far has done the trick.

There is a kernel module in CentOS 5 called ibm_acpi, it needs to be loaded with experimental features, so easiest way to do this is to edit (or create, he didn’t have the file initially, so open in vi/nano etc.)


And add the line;

modprobe ibm_acpi experimental=1

This will load the module each time in experimental mode. Dont’ forget to

chmod +x /etc/rc.modules

If it didn’t exist as it’s a script that needs to be run so has to have execute permissions. Next use an editor to open up /etc/rc.local and add the following line to it;

echo 0x2F 0x40 > /proc/acpi/ibm/ecdump

When the laptop reboots it’ll load the ibm_acpi module creating a new directory in /proc containing special files, for instance the fan info file located at /proc/acpi/ibm/fan (you can cat this file and it’ll list the fans RPM and what mode it is in).

What the echo command we entered in ecdump does is switch the fan into “disengaged” mode, which basically tells it to not bother with auto sensing when it should turn on and run in full speed mode instead, which is around the 6000rpm mark as opposed to 3000rpm in normal mode. so in this new disengaged mode you’ll get something like this from using cat on /proc/acpi/ibm/fan

status:         disabled
speed:          6357
commands:       enable, disable

Yes it does say disabled but that’s it’s disengaged mode. If at any point you want to temporarily go back to auto just do the following;

echo 0x2F 0x80 > /proc/acpi/ibm/ecdump

And to permanently leave it in auto mode just remove that line from /etc/rc.local

Hope this helps someone out and it should be relativly simple to port to other distros. Bear in mind that after kernel 2.6.22 ibm_acpi no longer exists and totally new functionality has been built in a thinkpad module, but for more info best off looking on the thinkpad wiki site at:

ThinkPad Wiki

Edit To Add Other Mode Available:

#(fan off – DONT DO THIS !!)

echo 0x2F 0x00 > /proc/acpi/ibm/ecdump

#(low speed)

echo 0x2F 0x02 > /proc/acpi/ibm/ecdump

#(medium speed)

echo 0x2F 0x04 > /proc/acpi/ibm/ecdump

# (maximum speed)

echo 0x2F 0x07 > /proc/acpi/ibm/ecdump

#(automatic – default)

echo 0x2F 0x80 > /proc/acpi/ibm/ecdump


echo 0x2F 0x40 > /proc/acpi/ibm/ecdump

Very quick note, just found a link to get Skype’s API integrated into Kontact so a simple click on a phone number in Kontact’s address book activates Skype. Very Cool ! 🙂


I made one minor change as I have already formatted my KDE numbers to have a plus. Just change this line if you have also:

number = ‘+’ + sys.argv[1]


number = sys.argv[1]

I might tweak this a bit to do it automagically… but then again maybe I won’t get around to it 😉

It’s my one year aniversary of not touching a Windows machine (I used to use them in work) but having started developing again I know get to work from home using my Linux machine… and I’m thankful for it ! I don’t fancy being part of either the Russian Mafia, Chinese Military or the soon to be US Air Force Botnet… Thanks guys but no.

Ask Not What Your Country Can Do For You.. But What Your Computer Can Do For Your Country

Bruce Schneier Chimes In : Unfortunalty it seems they do want to use public machine…I guess it’s a wait and see. Question will they team up with the AV vendors to allow it as a “legitimate” virus like what happened with Sony’s Rootkit.

I’ve been struggling (albeit not spending too much time) working on an issue on a Gutsy Server problem I’ve had. From one day to the next my SSH logins started asking me for a password. I had set up password-less logins with SSH keys.

In the logs I kept getting:

Authentication refused: bad ownership or modes for directory /home/username

It should have been a clue really… I checked and double checked that $HOME/.ssh might not be set to 0700, or the authorized_keys file might not be set to 0600. No joy… But the clue was really in the error. It was the ownership of my entire home directory, which although the owner is me and the group is also my username it apparently wasn’t good enough.

So chmod 700 /home/username fixed it…

Annoyingly easy !

UPDATE: Check no one has added themselves to your group in /etc/group… yep it’s a *special* account used by a couple of us, and one of the guys had added his own account to the group… tut tut 😉

That would explain the “Working From One Day To The Next” scenario !

If you followed my instructions to get the Plugin Architecture on Gutsy running you would have ended up running a “Middle Distro Deb” (Yes I made that up…no idea what you’d call it) of Cacti 0.8.7a2. When you do upgrade to Hardy they actually ended up switching to 0.8.7b due to some security fixes and improvments. Not a problem…

When you do the Distro Upgrade it’ll carry on like usual, next time you go to the Cacti web frontend it will do the upgrade process like usual. Now this is where you get a minor error:

[Fail] ALTER TABLE `graph_templates_item` ADD INDEX `task_item_id` ( `task_item_id` )

[Success] ALTER TABLE `data_input_data` ADD INDEX `t_value`(`t_value`)

Have no fear, the error occurs becasue when you did the upgrade from 0.8.6j (Gutsy’s version) to the 0.8.7a2 release it already too place. If you don’t believe me use MySQL’s command line util to view the indexes of that table with:

show index from graph_templates_item;

The Plugin Arch will need to be repatched over the code, which I’ll update ASAP.