Ok so I think this tops any script :p

Code:

#!/bin/sh
# $1 = namespace
# $2 = domain\username
# $3 = password
# $4 = target host
# $5 = WQL
# $6 = Number of | to cut to get desired result
# $7 = Result Name

RAW=$(wmic --namespace=$1 -U $2%$3 //$4 "$5")

ERROR=`echo $RAW | cut -f2- -d\ | tr ' ' '\n' | grep 'ERROR' | cut -f1 -d: | 
head -1`

if [ "$ERROR" != "ERROR" ]
        then
                RESULT=`echo $RAW | cut -d \| -f $6`
                RESULT=`echo $RESULT | cut -d \| -f 1`
                echo -n $RESULT | awk '{print "OK|'"$7"'=" $1}'
        else
                echo -n $RAW | awk '{print $RAW}'
fi




So, for example, to check the number of emails in an Exchange mailbox, I'd use 
this in a Command Template in Zenoss:


Code:

$$ZENHOME/libexec/check_wmic_anything 'root\MicrosoftExchangeV2' 
'${dev/zWinUser}' '${dev/zWinPassword}' ${dev/manageIp} "SELECT TotalItems From 
Exchange_Mailbox Where MailboxDisplayName='Administrator'" 11 Emails




Or, to check the wmic example of Win32_ComputerSystem:


Code:

$$ZENHOME/libexec/check_wmic_anything 'root\cimv2' '${dev/zWinUser}' 
'${dev/zWinPassword}' ${dev/manageIp} "SELECT * From Win32_ComputerSystem" 60 
AutomaticRebootCapibility




Enjoy! :)




-------------------- m2f --------------------

Read this topic online here:
http://community.zenoss.com/forums/viewtopic.php?p=12922#12922

-------------------- m2f --------------------



_______________________________________________
zenoss-users mailing list
[email protected]
http://lists.zenoss.org/mailman/listinfo/zenoss-users

Reply via email to