Package org.opennms.protocols.wmi
Class WmiManager
- java.lang.Object
-
- org.opennms.protocols.wmi.WmiManager
-
public class WmiManager extends java.lang.Object
This provides an easy abtraction of the WmiClient functionality. It allows programmers to make simple WMI Class + WMI Object queries and then measure the resulting values against parameters. The purpose of the WMI Manager is to provide poller-style functionality where low-level access to WBEM objects and methods is not essential.
- Author:
- Matt Raykowski, OpenNMS
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_SOCKET_TIMEOUT
The default socket timeout.
-
Constructor Summary
Constructors Constructor Description WmiManager(java.lang.String host, java.lang.String user, java.lang.String pass)
Constructor.WmiManager(java.lang.String host, java.lang.String user, java.lang.String pass, java.lang.String domain)
Constructor.WmiManager(java.lang.String host, java.lang.String user, java.lang.String pass, java.lang.String domain, java.lang.String matchType)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
closejava.lang.String
getHostName()
Returns the host name being used to connect to the remote service.java.lang.String
getMatchType()
getMatchTypejava.lang.String
getNamespace()
getNamespaceint
getTimeout()
Returns the TCP socket timeout used when connecting to the remote service.void
init()
This creates a new WmiClient and creates a connection to the host.void
init(IWmiClient client)
This is for tests to harness and create a mock client.static boolean
isValidMatchType(java.lang.String matchType)
isValidMatchTypestatic boolean
isValidOpType(java.lang.String opType)
isValidOpTypeWmiResult
performExecQuery(WmiParams params)
performExecQueryWmiResult
performInstanceOf(WmiParams params)
performInstanceOfWmiResult
performOp(WmiParams params)
performOpvoid
setHostName(java.lang.String host)
This method is used to set the host name to connect to for performing remote service checks.void
setMatchType(java.lang.String matchType)
setMatchTypevoid
setNamespace(java.lang.String namespace)
setNamespacevoid
setPassword(java.lang.String pass)
This method is used for setting the password used to perform service checks.void
setTimeout(int timeout)
This method is used to set the TCP socket timeout to be used when connecting to the remote service.
-
-
-
Constructor Detail
-
WmiManager
public WmiManager(java.lang.String host, java.lang.String user, java.lang.String pass)
Constructor.- Parameters:
host
- sets the host name to connect to.user
- sets the username to connect withpass
- sets the password to connect with.
-
WmiManager
public WmiManager(java.lang.String host, java.lang.String user, java.lang.String pass, java.lang.String domain)
Constructor.- Parameters:
host
- sets the host name to connect to.user
- sets the username to connect withpass
- sets the password to connect with.domain
- sets the domain to connect to.
-
WmiManager
public WmiManager(java.lang.String host, java.lang.String user, java.lang.String pass, java.lang.String domain, java.lang.String matchType)
Constructor.- Parameters:
host
- sets the host name to connect to.user
- sets the username to connect withpass
- sets the password to connect with.domain
- sets the domain to connect to.matchType
- the type of matching to be used for multiple results: all, none, some, one.
-
-
Method Detail
-
setPassword
public void setPassword(java.lang.String pass)
This method is used for setting the password used to perform service checks.- Parameters:
pass
- the password to use when performing service checks.
-
setHostName
public void setHostName(java.lang.String host)
This method is used to set the host name to connect to for performing remote service checks. This method must be called before calling the init() method or it will have no effect.- Parameters:
host
- the host name to connect to.- See Also:
init()
-
getHostName
public java.lang.String getHostName()
Returns the host name being used to connect to the remote service.- Returns:
- the host name being used to connect to the remote service.
-
setTimeout
public void setTimeout(int timeout)
This method is used to set the TCP socket timeout to be used when connecting to the remote service. This must be called before callinginit
or it will have no effect.- Parameters:
timeout
- the TCP socket timeout.
-
getTimeout
public int getTimeout()
Returns the TCP socket timeout used when connecting to the remote service.- Returns:
- the tcp socket timeout.
-
isValidMatchType
public static boolean isValidMatchType(java.lang.String matchType)
isValidMatchType
- Parameters:
matchType
- aString
object.- Returns:
- a boolean.
-
isValidOpType
public static boolean isValidOpType(java.lang.String opType)
isValidOpType
- Parameters:
opType
- aString
object.- Returns:
- a boolean.
-
init
public void init() throws WmiException
This creates a new WmiClient and creates a connection to the host.- Throws:
WmiException
- An exception will be thrown if the system is unable to look up the host and if J-Interop throws an exception this will re-throw that exception so that implementors need not know J-Interop exceptions.
-
init
public void init(IWmiClient client) throws WmiException
This is for tests to harness and create a mock client. Do not use!- Parameters:
client
- allows a IWmiClient to be pre-instantiated. Used for mock testing.- Throws:
WmiException
- is thrown if there are any problems connecting.
-
close
public void close() throws WmiException
close
- Throws:
WmiException
- if any.
-
performOp
public WmiResult performOp(WmiParams params) throws WmiException
performOp
- Parameters:
params
- aWmiParams
object.- Returns:
- a
WmiResult
object. - Throws:
WmiException
- if any.
-
performExecQuery
public WmiResult performExecQuery(WmiParams params) throws WmiException
performExecQuery
- Parameters:
params
- aWmiParams
object.- Returns:
- a
WmiResult
object. - Throws:
WmiException
- if any.
-
performInstanceOf
public WmiResult performInstanceOf(WmiParams params) throws WmiException
performInstanceOf
- Parameters:
params
- aWmiParams
object.- Returns:
- a
WmiResult
object. - Throws:
WmiException
- if any.
-
getMatchType
public java.lang.String getMatchType()
getMatchType
- Returns:
- the m_MatchType
-
setMatchType
public void setMatchType(java.lang.String matchType)
setMatchType
- Parameters:
matchType
- the m_MatchType to set
-
getNamespace
public java.lang.String getNamespace()
getNamespace
- Returns:
- the m_namespace
-
setNamespace
public void setNamespace(java.lang.String namespace)
setNamespace
- Parameters:
the
- m_namespace to set
-
-