org.networkupstools.jnut
Class Scanner

java.lang.Object
  extended by org.networkupstools.jnut.Scanner

public class Scanner
extends java.lang.Object

jNut scanner. Wrap calls to nut-scanner in java. Just, instantiate it, set options and nut-scanner path, then scan.

 Scanner scanner = new Scanner();
 scanner.setExecName("/usr/local/ups/bin/nut-scanner");
 scanner.setExecPath("/usr/local/ups/bin");
 scanner.setParam(Scanner.OPTION_MASK_CIDR, "192.168.1.1/24");
 Scanner.DiscoveredDevice[] devs = scanner.scan();
 

Author:
Emilien Kia

Nested Class Summary
static class Scanner.DiscoveredDevice
          Result of a scan.
 
Field Summary
static java.lang.String OPTION_END_IP
           
static java.lang.String OPTION_MASK_CIDR
           
static java.lang.String OPTION_NUT_UPSD_PORT
           
static java.lang.String OPTION_SCANNER_EXEC
           
static java.lang.String OPTION_SCANNER_PATH
           
static java.lang.String OPTION_SNMPv1_COMMUNITY
           
static java.lang.String OPTION_SNMPv3_AUTHENTICATION_PASSWORD
           
static java.lang.String OPTION_SNMPv3_AUTHENTICATION_PROTOCOL
           
static java.lang.String OPTION_SNMPv3_PRIVACY_PASSWORD
           
static java.lang.String OPTION_SNMPv3_PRIVACY_PROTOCOL
           
static java.lang.String OPTION_SNMPv3_SECURITY_LEVEL
           
static java.lang.String OPTION_SNMPv3_SECURITY_NAME
           
static java.lang.String OPTION_START_IP
           
static java.lang.String OPTION_TIMEOUT
           
static int SCAN_AVAHI
           
static int SCAN_COMPLETE
           
static int SCAN_IPMI
           
static int SCAN_OLDNUT
           
static int SCAN_SNMP
           
static int SCAN_USB
           
static int SCAN_XML
           
 
Constructor Summary
Scanner()
          Default constructor (scan for all device types).
Scanner(int scanType)
          Constructor with device types.
Scanner(int scanType, java.util.Map config)
          Constructor with device types and scan parameters.
 
Method Summary
 java.util.Map getConfig()
          Retrieve scanner extra parameters like snmp community name or passwords.
 java.lang.String getExecName()
          Retrieve nut-scanner executable name (with location if any).
 java.lang.String getExecPath()
          Retrieve nut-scanner executable path.
 java.lang.String getParam(java.lang.String name)
          Retrieve a scanner extra parameter.
 int getScanType()
          Retrieve the scan type.
 boolean hasParam(java.lang.String name)
          Test if a scanner has an extra parameter.
 void removeParam(java.lang.String name)
          Remove a scanner extra parameter.
 Scanner.DiscoveredDevice[] scan()
          Execute the scan.
 void setConfig(java.util.Map config)
          Set the scanner extra parameters.
 void setExecName(java.lang.String value)
          Set nut-scanner executable name (with location if any).
 void setExecPath(java.lang.String value)
          Set nut-scanner executable path.
 void setParam(java.lang.String name, java.lang.String value)
          Set a scanner extra parameter.
 void setScanType(int scanType)
          Set the scan type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SCAN_USB

public static final int SCAN_USB
See Also:
Constant Field Values

SCAN_SNMP

public static final int SCAN_SNMP
See Also:
Constant Field Values

SCAN_XML

public static final int SCAN_XML
See Also:
Constant Field Values

SCAN_OLDNUT

public static final int SCAN_OLDNUT
See Also:
Constant Field Values

SCAN_AVAHI

public static final int SCAN_AVAHI
See Also:
Constant Field Values

SCAN_IPMI

public static final int SCAN_IPMI
See Also:
Constant Field Values

SCAN_COMPLETE

public static final int SCAN_COMPLETE
See Also:
Constant Field Values

OPTION_SCANNER_EXEC

public static final java.lang.String OPTION_SCANNER_EXEC
See Also:
Constant Field Values

OPTION_SCANNER_PATH

public static final java.lang.String OPTION_SCANNER_PATH
See Also:
Constant Field Values

OPTION_TIMEOUT

public static final java.lang.String OPTION_TIMEOUT
See Also:
Constant Field Values

OPTION_START_IP

public static final java.lang.String OPTION_START_IP
See Also:
Constant Field Values

OPTION_END_IP

public static final java.lang.String OPTION_END_IP
See Also:
Constant Field Values

OPTION_MASK_CIDR

public static final java.lang.String OPTION_MASK_CIDR
See Also:
Constant Field Values

OPTION_SNMPv1_COMMUNITY

public static final java.lang.String OPTION_SNMPv1_COMMUNITY
See Also:
Constant Field Values

OPTION_SNMPv3_SECURITY_LEVEL

public static final java.lang.String OPTION_SNMPv3_SECURITY_LEVEL
See Also:
Constant Field Values

OPTION_SNMPv3_SECURITY_NAME

public static final java.lang.String OPTION_SNMPv3_SECURITY_NAME
See Also:
Constant Field Values

OPTION_SNMPv3_AUTHENTICATION_PROTOCOL

public static final java.lang.String OPTION_SNMPv3_AUTHENTICATION_PROTOCOL
See Also:
Constant Field Values

OPTION_SNMPv3_AUTHENTICATION_PASSWORD

public static final java.lang.String OPTION_SNMPv3_AUTHENTICATION_PASSWORD
See Also:
Constant Field Values

OPTION_SNMPv3_PRIVACY_PROTOCOL

public static final java.lang.String OPTION_SNMPv3_PRIVACY_PROTOCOL
See Also:
Constant Field Values

OPTION_SNMPv3_PRIVACY_PASSWORD

public static final java.lang.String OPTION_SNMPv3_PRIVACY_PASSWORD
See Also:
Constant Field Values

OPTION_NUT_UPSD_PORT

public static final java.lang.String OPTION_NUT_UPSD_PORT
See Also:
Constant Field Values
Constructor Detail

Scanner

public Scanner()
Default constructor (scan for all device types).


Scanner

public Scanner(int scanType)
Constructor with device types. Construct a scanner object with specifying what type of scan to do.

Parameters:
scanType - Type of scan, union of SCAN_* flags.

Scanner

public Scanner(int scanType,
               java.util.Map config)
Constructor with device types and scan parameters. Construct a scanner object with specifying what type of scan to do and extra scan parameters.

Parameters:
scanType - Type of scan, union of SCAN_* flags.
config - Map of extra parameters, names are OPTION_*.
Method Detail

getExecName

public java.lang.String getExecName()
Retrieve nut-scanner executable name (with location if any). Default to "nut-scanner".

Returns:
nut-scanner executable name

setExecName

public void setExecName(java.lang.String value)
Set nut-scanner executable name (with location if any).

Parameters:
value - nut-scanner executable name

getExecPath

public java.lang.String getExecPath()
Retrieve nut-scanner executable path. The directory in which nut-scanner will be launched.

Returns:
nut-scanner executable path

setExecPath

public void setExecPath(java.lang.String value)
Set nut-scanner executable path. The directory in which nut-scanner will be launched.

Parameters:
value - nut-scanner executable path

getConfig

public java.util.Map getConfig()
Retrieve scanner extra parameters like snmp community name or passwords.

Returns:
Map of parameters.

setConfig

public void setConfig(java.util.Map config)
Set the scanner extra parameters.

Parameters:
map - Map of parameters.

setParam

public void setParam(java.lang.String name,
                     java.lang.String value)
Set a scanner extra parameter.

Parameters:
name - Name of the parameter.
value - Value of the parameter.

removeParam

public void removeParam(java.lang.String name)
Remove a scanner extra parameter.

Parameters:
name - Name of the parameter to remove.

getParam

public java.lang.String getParam(java.lang.String name)
Retrieve a scanner extra parameter.

Parameters:
name - Name of the parameter.
Returns:
Value of the parameter, null if not found.

hasParam

public boolean hasParam(java.lang.String name)
Test if a scanner has an extra parameter.

Parameters:
name - Name of the parameter.
Returns:
True if the scanner has the parameter set.

getScanType

public int getScanType()
Retrieve the scan type.

Returns:
Union of SCAN_* flags.

setScanType

public void setScanType(int scanType)
Set the scan type.

Parameters:
scanType - Union of SCAN_* flags.

scan

public Scanner.DiscoveredDevice[] scan()
                                throws java.io.IOException
Execute the scan.

Returns:
Array of found DiscoveredDevice, null if a problem occurs, empty if no one found.
Throws:
java.io.IOException


Copyright © 2011. All Rights Reserved.