Tuesday, March 27, 2007

Using PowerShell with HP OpenView Operations Windows agents

I've been wanting to try using PowerShell to do advanced system monitoring, but only got around to it this week.

One of the first things to do was to test how PowerShell could interface with the HP OVO Windows agent.

I found out recently that version 7.20 or newer of the Windows based agents had a automation library included, aka COM interface (I hope I'm using the terms properly).

I first tried to load the automation library straight from PowerShell, but that failed:

PSH> $ovo=new-object -com ovoautomation.opcmsg
PSH> $ovo|gm
   TypeName: System.__ComObject#{bb03cab1-2606-4388-bbbc-2b5af2321464}
Name         MemberType Definition
----         ---------- ----------
Send         Method     void Send ()
Application  Property    {get} {set}
MessageGroup Property    {get} {set}
MessageId    Property   string MessageId () {get}
MessageText  Property    {get} {set}
NodeName     Property    {get} {set}
Object       Property    {get} {set}
OptVar       Property    {get} {set}
ServiceName  Property    {get} {set}
Severity     Property    {get} {set}

PSH> $ovo.messagetext="testing"
Exception setting "MessageText": "Type mismatch. (Exception from HRESULT:
0x80020005 (DISP_E_TYPEMISMATCH))"
At line:1 char:6
+ $ovo.m <<<< essagetext="testing"
PSH>

[end display of PSH code]

You'll note that 'Definition' section doesn't look very complete if compared to the IE COM object.  I don't know if that makes a difference.

OK, so that doesn't work...

I went to the HP ITRC forums and asked whether anyone had tried using the OVO agents with PowerShell.  Drew Dimmick replied that he was getting the same error, but also pointed out a link to www.ovinternals.com (free account required to download), where there was a managed code assembly available that exposes the OVO agent API.  I retrieved the OVAgent.zip file and tried it out...  It worked perfectly:

PSH>[void][reflection.assembly]::loadfrom("$($pwd.path)\ovagent.dll")
PSH>$ovo=new-object ovinternals.ovagent.submitmessage
PSH>$ovo.group="testing"
PSH>$ovo.send("normal","app","obj","text")
PSH>$ovo.lastsentmessageid
f6df8000-d938-71db-1286-ac1dd0640000
PSH>

[end of display of PSH code]

I only tried the messaging inteface, but it also appears you have an API for CODA performance logging, as well as an API for the monitoring agent (opcmona).

Friday, March 23, 2007

BlackBerry Enterprise Server SNMP agent extension

I was working on a trouble with doing some SNMP monitoring of a BlackBerry Entrprise Server 4.x.  I noticed I could not do any typical commands like get or walk on a particular server.  I read and re-read the vendor documentation, and still could not get BES SNMP to work, while it was working fine on another BES server we had.

Turned out that the server that didn't work had a BlackBerryServerSNMPAgent.dll version of 4.x, while the DLL that did work on another server was 2.x.  I copied the 2.x DLL over to the new server, restarted SNMP, and all is well.

So either the MIB variables are different, or there's something wrong with the 4.x DLL.  Perhaps the 4.x DLL has more 'monitoring points' or other added features, but what I found in the 2.x version met all my requirements.

(I intend on tying this into PowerShell for some advanced monitoring of BES.  It appears the only way to do monitoring of the client license usage might be via SNMP.)

(Also just blogging this to post this somewhere on the web.)

Monday, March 12, 2007

New NetCmdlets beta

I've previously blogged about NetCmdlets before.  They have just released beta 3 of their PowerShell extensions.

Definitely something worth trying out for rich networking-based cmdlets extensions.

Saturday, March 10, 2007

Cool application: PowerGUI (www.powergui.org)

There's a new project out there still in a 'closed' beta.  It is closed, but you can go to www.powergui.org and request an account.

From the FAQ: "PowerGUI is an extensible graphical administrative console for managing systems based on Windows PowerShell. These include Windows OS (XP, 2003, Vista), Exchange 2007, Operations Manager 2007 and other new systems from Microsoft. The tool allows to use the rich capabilities of Windows PowerShell in a familiar and intuitive GUI console."

This is a pretty good idea on using a graphical method to represent objects from cmdlets.

You can find a Exchange 2007, and I think it is pretty powerfull as far as viewing and actually being able to make modifications.

I might blog about this a bit more this week if I find the time.

Wednesday, March 7, 2007

Comments feed in Community Server

With some help from Lance, I'm posting an entry on how to get access to an RSS feed of comments from the great online forum product Community Server.  Apparently, their newer version (currently in beta) makes this available via a viewable RSS feed link.

Very simple script/example below.  It will print out the blog post titles, then the next line will be the RSS feed address to the comments.

PowerShell script:

[string]$url="http://powergadgets.com/csPg/blogs/powergadgets/rss.aspx"
$wc = new-Object System.Net.WebClient
[xml]$nl = $wc.DownloadString($url)
$nl.rss.channel.item|%{$_.title,$_.commentRss}

[end script]

Thursday, March 1, 2007

Another PowerGadgets example

I've blogged a few times before about the 2007 Microsoft Scripting Games.  There was 4 categories this year, and I originally thought I was going to map all the data like I previously did.  Instead, I though I'd do something different: represent the number of participants per country per category in a line graph using PowerGadgets.

Here's the finished product: all countries (with more than 5 total entrants).

Legend:

psaentries: PowerShell advanced, psbentries: PowerShell beginner, vbaentries: VBScript advanced,  and vbbentries: VBScript beginner.  total is just the sum of the former 4 values.

Here's an example of the 'mouse-over' features.  What I did here, was put my mouse over  psaentries in the legend box: PowerShell advanced entries.

Here's another advanced feature where I add a "data grid", so I can view all the data in a table format just below the graph:data grid option.

And finally, one more advanced feature where I do a mouse-over of a particular data point, and I get: a popup tooltip.

To keep the graph "less busy", I've only added countries who had a total number of participants of 5 or more.

All the entries for each category are here: VBScript beginner, VBScript advanced, PowerShell beginner, and PowerShell advanced.

Inspired by /\/\o\/\/, here's the script I used:

$countries=@{}

[string]$pre_url="http://www.microsoft.com/technet/scriptcenter/funzone/games/games07/"
[string]$post_url="scores.mspx"

$categories=@("psa","psb","vba","vbb")

$j=0
$z=0

foreach ($category in $categories){
[string]$url=${pre_url}+${category}+${post_url}
$wc = new-Object System.Net.WebClient
$nl = $wc.DownloadString("$url")
$r = [regex]'l">(.*?)</p'
$m = $r.Matches($nl)
$l = $m |% {$_.groups[1].value}
$list = @()
foreach ($i in 13..($l.count -1) ) {
$Record = new-Object -typename System.Object
$Record | add-Member -memberType noteProperty -name Name -Value $m[$i].groups[1].value
[void] $foreach.MoveNext()
$Record | add-Member -memberType noteProperty -name Country -Value $m[$foreach.current].groups[1].value
1..10 |% {[void] $foreach.MoveNext();$Record | add-Member -memberType noteProperty -name "E$_" -Value $m[$foreach.current].groups[1].value}
[void] $foreach.MoveNext();$Record | add-Member -memberType noteProperty -name "Total" -Value $m[$foreach.current].groups[1].value
$list += $record
}
$list|group Country|`
%{if($countries[$_.name] -eq $null){$countries[$_.name]="0,0,0,0,0"}
$country_val0=$countries[$_.name].split(',')[0]
$country_val1=$countries[$_.name].split(',')[1]
$country_val2=$countries[$_.name].split(',')[2]
$country_val3=$countries[$_.name].split(',')[3]
$cur_count=$_.count
set-variable country_val$z $cur_count
$countries[$_.name]="${country_val0},${country_val1},${country_val2},${country_val3},0"
}
$j=$j+2
$z++
}

$arr_countries=@($countries.keys)

$arr_countries|`
%{[string]$curr_values=$countries[$_]
[int]$country_tot0=$curr_values.split(',')[0]
[int]$country_tot1=$curr_values.split(',')[1]
[int]$country_tot2=$curr_values.split(',')[2]
[int]$country_tot3=$curr_values.split(',')[3]
[int]$country_sum=${country_tot0}+${country_tot1}+${country_tot2}+${country_tot3}
$countries[$_]="${country_tot0},${country_tot1},${country_tot2},${country_tot3},${country_sum}"
}

$listing=@()

foreach ($arr_country in $arr_countries){
[string]$cur_country=$countries[$arr_country]
[int]$cur_country0=$cur_country.split(',')[0]
[int]$cur_country1=$cur_country.split(',')[1]
[int]$cur_country2=$cur_country.split(',')[2]
[int]$cur_country3=$cur_country.split(',')[3]
[int]$cur_country4=$cur_country.split(',')[4]
$record=new-object -typename system.object
$record|add-member -membertype noteproperty -name Country -value $arr_country
$record|add-member -membertype noteproperty -name PSAEntries -value $cur_country0
$record|add-member -membertype noteproperty -name PSBEntries -value $cur_country1
$record|add-member -membertype noteproperty -name VBAEntries -value $cur_country2
$record|add-member -membertype noteproperty -name VBBEntries -value $cur_country3
$record|add-member -membertype noteproperty -name Total -value $cur_country4
$listing+=$record
}

$listing|?{$_.Total -ge 5}|`
out-chart -palette highcontrast -label country -values psaentries,psbentries,vbaentries,vbbentries,total -AllSeries_Gallery Lines -AllSeries_PointLabels_Visible false

[end code]

(I'm still trying to figure out blogspot code formatting...  Leave a comment if you'd like me to send you the script.)