public class NsclientManager extends Object
This class is designed to be used by plugins, services and programs to perform checks against an NSClient service.
To use it you must first create an instance of the manager with the host,
port and/or password. Then you can set the timeout for the socket, if you
want to override DEFAULT_SOCKET_TIMEOUT. Once you have set up the manager,
you call the init() method to connect to the service. Once connected you
use the processCheckCommand() method to receive a NsclientPacket object
containing the response and the result code. Here's an example of using
this manager: NsclientCheckParams params = new
NsclientCheckParams(critPerc, warnPerc, parameter); NsclientManager client =
new NsclientManager(host.getHostAddress(), port); client.init();
NsclientPacket
pack=client.processCheckCommand(NsclientManager.convertStringToType(command),
params);
Modifier and Type | Field and Description |
---|---|
static String |
CHECK_CLIENTVERSION
The ID for checking the remote client version.
|
static String |
CHECK_COUNTER
The ID for checking the value of a remote Perfmon counter.
|
static String |
CHECK_CPULOAD
The ID for checking the remote CPU usage.
|
static String |
CHECK_FILEAGE
The ID for checking the age of a remote file.
|
static String |
CHECK_FILESIZE
The ID for checking the size of a directory.
|
static String |
CHECK_INSTANCES
This check type is used by the NSClient developers as a utility for an
easy remote method of looking up potential COUNTER instances.
|
static String |
CHECK_MEMUSE
The ID for checking the state of the remote memory usage.
|
static String |
CHECK_NONE
Default check type.
|
static String |
CHECK_PROCSTATE
The ID for checking the state of a remote process.
|
static String |
CHECK_SERVICESTATE
The ID for checking the state of a remote service.
|
static String |
CHECK_UPTIME
The ID for checking the remote uptime.
|
static String |
CHECK_USEDDISKSPACE
The ID for checking the remote used disk space.
|
static Map<String,String> |
CheckStrings
Stores the String -> CHECK_ id mappings for lookups.
|
static int |
DEFAULT_PORT
The default NSClient TCP port.
|
static int |
DEFAULT_SOCKET_TIMEOUT
The default socket timeout.
|
Constructor and Description |
---|
NsclientManager(String host)
Constructor.
|
NsclientManager(String host,
int port)
Constructor.
|
NsclientManager(String host,
int port,
String pass)
Constructor.
|
NsclientManager(String host,
String pass)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the socket.
|
static String |
convertStringToType(String type)
This method uses the CheckStrings HashMap to convert from a string to a
short value.
|
static String |
convertTypeToString(String type)
This method uses CheckStrings to convert from a short value such as
CHECK_CLIENTVERSION to the a string, for example "CLIENTVERSION"
|
String |
getHostName()
Returns the host name being used to connect to the remote service.
|
int |
getPortNumber()
Returns the port being used to connect to the remote service.
|
int |
getTimeout()
Returns the TCP socket timeout used when connecting to the remote
service.
|
void |
init()
This method creates a new socket and attempts to connect to the remote
service.
|
NsclientPacket |
processCheckCommand(String type,
NsclientCheckParams param)
This method determines which check method to call to create a request,
send to the server and process the results.
|
void |
setHostName(String host)
This method is used to set the host name to connect to for performing
remote service checks.
|
void |
setPassword(String pass)
This method is used for setting the password used to perform service
checks.
|
void |
setPortNumber(int port)
This method is used for overriding the port that is used to connect to
the remote service.
|
void |
setTimeout(int timeout)
This method is used to set the TCP socket timeout to be used when
connecting to the remote service.
|
public static final int DEFAULT_SOCKET_TIMEOUT
public static final int DEFAULT_PORT
public static final String CHECK_NONE
public static final String CHECK_CLIENTVERSION
public static final String CHECK_CPULOAD
public static final String CHECK_UPTIME
public static final String CHECK_USEDDISKSPACE
public static final String CHECK_SERVICESTATE
public static final String CHECK_PROCSTATE
public static final String CHECK_MEMUSE
public static final String CHECK_COUNTER
public static final String CHECK_FILEAGE
public static final String CHECK_INSTANCES
public static final String CHECK_FILESIZE
public NsclientManager(String host)
host
- sets the host name to connect to.public NsclientManager(String host, int port)
host
- sets the host name to connect to.port
- sets the port number to connect using.public NsclientManager(String host, int port, String pass)
host
- sets the host name to connect to.port
- sets the port number to connect using.pass
- sets the password to use when performing checks.public static String convertTypeToString(String type)
type
- the CHECK_ type to look up in the CheckStrings map.CheckStrings
,
convertStringToType
public static String convertStringToType(String type)
type
- A string to look up a CHECK_ value from the CheckStrings
HashMap.CheckStrings
,
convertTypeToString
public void setPassword(String pass)
pass
- the password to use when performing service checks.public void setPortNumber(int port)
port
- the remote service port.public int getPortNumber()
init
public void setHostName(String host)
host
- the host name to connect to.init
public String getHostName()
public void setTimeout(int timeout)
init
or it will have no effect.timeout
- the TCP socket timeout.public int getTimeout()
public void init() throws NsclientException
NsclientException
- if the hostname is unknown if the connection is refused if
there is no route to the host if the host did not respond
if there was an unexpected IO error. The thrown exception
contains the causing exception.public void close()
public NsclientPacket processCheckCommand(String type, NsclientCheckParams param) throws NsclientException
type
- the short ID of the type of check to be processed.param
- the object containing the parameters for performing checks
on the respones from the remote service.NsclientException
- this method rethrows org.opennms.netmgt.poller.nsclient.NsclientExceptions caused by the check
commands.Copyright © 2021. All rights reserved.