Login with Facebook

Tuesday, February 1, 2011

List all policies deployed on your OMW Managed Nodes

Lots of questions has been raised during last few weeks in ITRC about OMW  Nodes - Policies relationship
One of the questions was about how to list all Policies assigned for certain node or all nodes
the answer was typically there is a default report built-in HP Reporter
This report is called OVO/Windows 7.5 ConfInstalledPol "OVO/Windows 7.5 Installed Policies per Node"
You can also rerun the report as Excel.
367640
But the issue is sometimes you need a report for  a certain node or all nodes and HP Reporter requires certain configuration (very easy) but I have given also another solution
To list all policies deployed on nodes based on latest Policy Synchronization

'//get the name of the managed node from the command line
Dim argsObj
Set argsObj=WScript.Arguments
If argsObj.Count=0 Then
WScript.echo "Usage: cscript.exe RedployAllPolicies.vbs <nodeNameList>"
WScript.Quit (1)
End If
'//create connection to policy management server 
Dim PMAD
Set PMAD = CreateObject("PMAD.OvPmdPolicyManager")
PMAD.ConnectDB
'//access the managed node in WMI
Dim objLocator
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Dim objNode
Set objNode = objLocator.ConnectServer("", "root\HewlettPackard\OpenView\data", "", "")
objNode.Security_.impersonationlevel = 3
'//iterate over the specified node list
Dim nodeName
Dim numOfNodes
For numOfNodes = 0 To argsObj.Count - 1
'//get the primary node name as it was specified on the command line
nodeName = argsObj(numOfNodes)
'//get the node from WMI
Dim msgQuery
msgQuery = "Select * from ov_managednode where primarynodename = """ & nodeName & """"
Dim objNodeList
Set objNodeList = objNode.ExecQuery(msgQuery)
'//get the GUID of the managed node object
Dim nodeGuid
Dim wmiNode
For Each wmiNode In objNodeList
'//assign the node GUID to the variable "nodeGuid"
nodeGuid = wmiNode.Name  
'//other node properties, such as system type or OS type, can be determine the same way
'//for example, osType = wmiNode.OSType or sysType = wmiNode.SystemType)
Next
'//release objects
Set wmiNode = Nothing
Set objNodeList = Nothing
If PMAD.DBConnected And nodeGuid <> "" Then
'//get the pmad node object, or create it if it does not yet exist)
Dim node
Set node = PMAD.CreateNode(nodeGuid)
'//get the list of policies that are currently installed on the node
Dim policyList
policyList = PMAD.CVar(node.GetPolicyList)
WScript.echo "The following policies are redeployed on node '" & nodeName & "':" & vrLf
Dim policy
Dim policyObj
Dim policyString
For Each policy In policyList
'//get the policy object
Set policyObj = policy
'//print out policy that is redployed
policyString = "     " & policyObj.GetName & "  " & policyObj.GetVersionString & vrLf
WScript.echo policyString
Next
WScript.echo "  " & vrLf
Set policy = Nothing
Set policyList = Nothing
Set node = Nothing
Else
If nodeGuid = "" Then
WScript.echo "Error: The node '" & nodeName & "' that you specified on the command line cannot be found in WMI!"
Else
WScript.echo "Error: Unable to connect to the policy management server!"
End If
End If
Next
'//release objects
Set objNode = Nothing
Set objLocator = Nothing
Set PMAD = Nothing

Typical usage: cscript.exe ListNodePolicies.vbs nodename


image

Also with a little modification to the script we can list all nodes
Dim argsObj
Set argsObj=WScript.Arguments
If argsObj.Count>0 Then
WScript.echo "Usage: cscript.exe ListAllNodesWithPolicies.vbs"
WScript.Quit (1)
End If
'//create connection to policy management server 
Dim PMAD
Set PMAD = CreateObject("PMAD.OvPmdPolicyManager")
PMAD.ConnectDB
'//access the managed node in WMI
Dim objLocator
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Dim objNode
Set objNode = objLocator.ConnectServer("", "root\HewlettPackard\OpenView\data", "", "")
objNode.Security_.impersonationlevel = 3
Dim nodeName
Dim numOfNodes
Dim msgQuery
msgQuery = "Select * from ov_managednode"
Dim objNodeList
Set objNodeList = objNode.ExecQuery(msgQuery)
Dim nodeGuid
Dim wmiNode
For Each wmiNode In objNodeList
nodeGuid = wmiNode.Name  
nodeName = wmiNode.primarynodename 
If PMAD.DBConnected And nodeGuid <> "" Then
'//get the pmad node object, or create it if it does not yet exist)
Dim node
Set node = PMAD.CreateNode(nodeGuid)
'//get the list of policies that are currently installed on the node
Dim policyList
policyList = PMAD.CVar(node.GetPolicyList)
WScript.echo "The following policies are redeployed on node '" & nodeName & "':" & vrLf
Dim policy
Dim policyObj
Dim policyString
For Each policy In policyList
'//get the policy object
Set policyObj = policy
'//print out policy that is redployed
policyString = "     " & policyObj.GetName & "  " & policyObj.GetVersionString & vrLf
WScript.echo policyString
Next
WScript.echo "  " & vrLf
Set policy = Nothing
Set policyList = Nothing
Set node = Nothing
Else
If nodeGuid = "" Then
WScript.echo "Error: The node '" & nodeName & "' that you specified on the command line cannot be found in WMI!"
Else
WScript.echo "Error: Unable to connect to the policy management server!"
End If
End If
Next
Here below of screenshot for the above script:

image

Some nodes displayed above without Policies because they are dummies I created for testing purposes.

5 comments:

Anonymous said...

Thanks Mahmoud...I am going to post the question on itrc fourum but thought to check ypur first and I got it....


Dharmendra

Anonymous said...

EventID: 0x00000400 (1024) - Messages are discarded because of duplicate nodes
in DB.

Please advise

sachinvichu said...

how to display the contents of teh parm file in an AIX maanaged node from OMW 9 server?

Unknown said...

Great effort :)
Thanks.

Tamilan said...

Lovely VB!! Thanks much Mahmoud.

Post a Comment