org.nervousync.beans.snmp.TargetHost Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of utils-jdk11 Show documentation
Show all versions of utils-jdk11 Show documentation
Java utility collections, development by Nervousync Studio (NSYC)
/*
* Licensed to the Nervousync Studio (NSYC) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.nervousync.beans.snmp;
import java.io.Serializable;
import org.nervousync.enumerations.net.IPProtocol;
import org.nervousync.enumerations.snmp.SNMPVersion;
import org.nervousync.enumerations.snmp.auth.SNMPAuthProtocol;
import org.nervousync.enumerations.snmp.auth.SNMPAuthType;
import org.nervousync.enumerations.snmp.auth.SNMPPrivProtocol;
/**
* SNMP Target Host Define
* SNMP目标主机定义
*
* @author Steven Wee [email protected]
* @version $Revision: 1.1.2 $ $Date: Sep 25, 2022 21:47:36 $
*/
public final class TargetHost implements Serializable {
/**
* Serial version UID
* 序列化UID
*/
private static final long serialVersionUID = -7043141633658888918L;
/**
* Default port number of SNMP
* 默认的SNMP端口号
*/
private static final int DEFAULT_SNMP_PORT = 161;
/**
* IP Protocol
* IP协议
*/
private final IPProtocol protocol;
/**
* Target Host IP Address
* 目标主机IP地址
*/
private final String ipAddress;
/**
* Target Host Community String
* 目标主机的查询密码
*/
private final String community;
/**
* Target Host Port Number
* 目标主机端口号
*/
private final int port;
/**
* Request Retry Limit Times
* 请求失败重试次数
*/
private final int retries;
/**
* Request Timeout
* 请求超时时间
*/
private final long timeOut;
/**
* SNMP Authentication Type
* SNMP验证类型
*/
private SNMPAuthType auth = SNMPAuthType.NOAUTH_NOPRIV;
/**
* SNMP Authentication Protocol
* SNMP验证协议
*/
private SNMPAuthProtocol authProtocol = null;
/**
* SNMP Authentication Password
* SNMP验证密码
*/
private String authPassword = null;
/**
* Type of encryption for the privacy password if authentication level is AUTH_PRIV
* 私有密码的加密方式,当验证类型为AUTH_PRIV时有效
*/
private SNMPPrivProtocol privProtocol = null;
/**
* SNMP Private Password. The minimum length of the Priv Password must be eight characters.
* SNMP私有密码。密码长度必须大于等于8个字符
*/
private String privPassword = null;
/**
* Target Host SNMP Version. Default: 2c
* 目标主机SNMP版本号。默认:2c
*/
private SNMPVersion version = SNMPVersion.VERSION2C;
/**
* Private constructor for TargetHost
* TargetHost的私有构造函数
*
* @param protocol IP Protocol
* IP协议
* @param ipAddress Target Host IP Address
* 目标主机IP地址
* @param community Target Host Community String
* 目标主机的查询密码
* @param port Target Host Port Number
* 目标主机端口号
* @param retries Request Retry Limit Times
* 请求失败重试次数
* @param timeOut Request Timeout
* 请求超时时间
*/
private TargetHost(final IPProtocol protocol, final String ipAddress, final String community,
final int port, final int retries, final long timeOut) {
this.protocol = protocol;
this.ipAddress = ipAddress;
this.community = community;
this.port = port <= 0 ? DEFAULT_SNMP_PORT : port;
this.retries = retries <= 0 ? 1 : retries;
this.timeOut = timeOut <= 0L ? 1000L : timeOut;
}
/**
* Static method for create TargetHost instance of localhost
* Using default community string: "public", default port number: 161, retry time: 1, default timeout: 1000
* 静态方法用于创建本地主机的TargetHost实例对象
* 使用默认的查询密码:"public",默认的端口号:161,默认重试次数:1,默认超时时间:1000
*
* @param protocol IP Protocol
* IP协议
*
* @return Generated TargetHost instance
* 生成的TargetHost实例对象
*/
public static TargetHost local(final IPProtocol protocol) {
return local(protocol, "public", DEFAULT_SNMP_PORT, 1, 1000L);
}
/**
* Static method for create TargetHost instance of localhost
* Using given community string, default port number: 161, retry time: 1, default timeout: 1000
* 静态方法用于创建本地主机的TargetHost实例对象
* 使用给定的查询密码,默认的端口号:161,默认重试次数:1,默认超时时间:1000
*
* @param protocol IP Protocol
* IP协议
* @param community Target Host Community String
* 目标主机的查询密码
*
* @return Generated TargetHost instance
* 生成的TargetHost实例对象
*/
public static TargetHost local(final IPProtocol protocol, final String community) {
return local(protocol, community, DEFAULT_SNMP_PORT, 1, 1000L);
}
/**
* Static method for create TargetHost instance of localhost
* Using given community string and port number, retry time: 1, default timeout: 1000
* 静态方法用于创建本地主机的TargetHost实例对象
* 使用给定的查询密码和端口号,默认重试次数:1,默认超时时间:1000
*
* @param protocol IP Protocol
* IP协议
* @param community Target Host Community String
* 目标主机的查询密码
* @param port Target Host Port Number
* 目标主机端口号
*
* @return Generated TargetHost instance
* 生成的TargetHost实例对象
*/
public static TargetHost local(final IPProtocol protocol, final String community, final int port) {
return local(protocol, community, port, 1, 1000L);
}
/**
* Static method for create TargetHost instance of localhost
* Using given community string and port number, retry times and timeout value
* 静态方法用于创建本地主机的TargetHost实例对象
* 使用给定的查询密码和端口号,重试次数以及超时时间
*
* @param protocol IP Protocol
* IP协议
* @param community Target Host Community String
* 目标主机的查询密码
* @param port Target Host Port Number
* 目标主机端口号
* @param retries Request Retry Limit Times
* 请求失败重试次数
* @param timeOut Request Timeout
* 请求超时时间
*
* @return Generated TargetHost instance
* 生成的TargetHost实例对象
*/
public static TargetHost local(final IPProtocol protocol, final String community, final int port,
final int retries, final long timeOut) {
return new TargetHost(protocol, "127.0.0.1", community, port, retries, timeOut);
}
/**
* Static method for create TargetHost instance of remote host address
* Using default community string: "public", default port number: 161, retry time: 1, default timeout: 1000
* 静态方法用于创建目标主机的TargetHost实例对象
* 使用默认的查询密码:"public",默认的端口号:161,默认重试次数:1,默认超时时间:1000
*
* @param protocol IP Protocol
* IP协议
* @param ipAddress Target Host IP Address
* 目标主机IP地址
*
* @return Generated TargetHost instance
* 生成的TargetHost实例对象
*/
public static TargetHost remote(final IPProtocol protocol, final String ipAddress) {
return remote(protocol, ipAddress, "public");
}
/**
* Static method for create TargetHost instance of remote host address
* Using given community string, default port number: 161, retry time: 1, default timeout: 1000
* 静态方法用于创建目标主机的TargetHost实例对象
* 使用给定的查询密码,默认的端口号:161,默认重试次数:1,默认超时时间:1000
*
* @param protocol IP Protocol
* IP协议
* @param ipAddress Target Host IP Address
* 目标主机IP地址
* @param community Target Host Community String
* 目标主机的查询密码
*
* @return Generated TargetHost instance
* 生成的TargetHost实例对象
*/
public static TargetHost remote(final IPProtocol protocol, final String ipAddress, final String community) {
return remote(protocol, ipAddress, community, DEFAULT_SNMP_PORT, 1, 1000L);
}
/**
* Static method for create TargetHost instance of remote host address
* Using given community string and port number, retry time: 1, default timeout: 1000
* 静态方法用于创建目标主机的TargetHost实例对象
* 使用给定的查询密码和端口号,默认重试次数:1,默认超时时间:1000
*
* @param protocol IP Protocol
* IP协议
* @param ipAddress Target Host IP Address
* 目标主机IP地址
* @param community Target Host Community String
* 目标主机的查询密码
* @param port Target Host Port Number
* 目标主机端口号
*
* @return Generated TargetHost instance
* 生成的TargetHost实例对象
*/
public static TargetHost remote(final IPProtocol protocol, final String ipAddress, final String community, final int port) {
return remote(protocol, ipAddress, community, port, 1, 1000L);
}
/**
* Static method for create TargetHost instance of remote host address
* Using given community string and port number, retry times and timeout value
* 静态方法用于创建目标主机的TargetHost实例对象
* 使用给定的查询密码和端口号,重试次数以及超时时间
*
* @param protocol IP Protocol
* IP协议
* @param ipAddress Target Host IP Address
* 目标主机IP地址
* @param community Target Host Community String
* 目标主机的查询密码
* @param port Target Host Port Number
* 目标主机端口号
* @param retries Request Retry Limit Times
* 请求失败重试次数
* @param timeOut Request Timeout
* 请求超时时间
*
* @return Generated TargetHost instance
* 生成的TargetHost实例对象
*/
public static TargetHost remote(final IPProtocol protocol, final String ipAddress, final String community,
final int port, final int retries, final long timeOut) {
return new TargetHost(protocol, ipAddress, community, port, retries, timeOut);
}
/**
* Getter method for IP Protocol
* IP协议的Getter方法
*
* @return IP Protocol
* IP协议
*/
public IPProtocol getProtocol() {
return protocol;
}
/**
* Getter method for target host ip address
* 目标主机IP地址的Getter方法
*
* @return Target Host IP Address
* 目标主机IP地址
*/
public String getIpAddress() {
return ipAddress;
}
/**
* Getter method for community string
* 查询密码的Getter方法
*
* @return Target Host Community String
* 目标主机的查询密码
*/
public String getCommunity() {
return community;
}
/**
* Getter method for authentication type
* 身份验证方式的Getter方法
*
* @return SNMP Authentication Type
* SNMP验证类型
*/
public SNMPAuthType getAuth() {
return auth;
}
/**
* Getter method for authentication protocol
* 身份验证协议的Getter方法
*
* @return SNMP Authentication Protocol
* SNMP验证协议
*/
public SNMPAuthProtocol getAuthProtocol() {
return authProtocol;
}
/**
* Getter method for authentication password
* 身份验证密码的Getter方法
*
* @return SNMP Authentication Password
* SNMP验证密码
*/
public String getAuthPassword() {
return authPassword;
}
/**
* Getter method for type of encryption for the privacy password
* 私有密码加密方式的Getter方法
*
* @return Type of encryption for the privacy password if authentication level is AUTH_PRIV
* 私有密码的加密方式,当验证类型为AUTH_PRIV时有效
*/
public SNMPPrivProtocol getPrivProtocol() {
return privProtocol;
}
/**
* Getter method for SNMP Private Password
* SNMP私有密码的Getter方法
*
* @return SNMP Private Password. The minimum length of the Priv Password must be eight characters.
* SNMP私有密码。密码长度必须大于等于8个字符
*/
public String getPrivPassword() {
return privPassword;
}
/**
* Getter method for SNMP version
* SNMP版本号的Getter方法
*
* @return Target Host SNMP Version. Default: 2c
* 目标主机SNMP版本号。默认:2c
*/
public SNMPVersion getVersion() {
return version;
}
/**
* Setter method for SNMP version
* SNMP版本号的Setter方法
*
* @param version Target Host SNMP Version.
* 目标主机SNMP版本号。
*/
public void setVersion(final SNMPVersion version) {
this.version = version;
}
/**
* Getter method for Target Host Port number
* 目标主机端口号的Getter方法
*
* @return Target Host Port Number
* 目标主机端口号
*/
public int getPort() {
return port;
}
/**
* Getter method for retry limit times
* 重试次数的Getter方法
*
* @return Request Retry Limit Times
* 请求失败重试次数
*/
public int getRetries() {
return retries;
}
/**
* Getter method for request timeout
* 请求超时时间的Getter方法
*
* @return Request Timeout
* 请求超时时间
*/
public long getTimeOut() {
return timeOut;
}
/**
* Configure authentication information using authentication type: SNMPAuthType.AUTH_NOPRIV
* 设置身份验证信息,使用身份验证类型为:SNMPAuthType.AUTH_NOPRIV
*
* @param authProtocol SNMP Authentication Type
* SNMP验证类型
* @see org.nervousync.enumerations.snmp.auth.SNMPAuthProtocol
* @param authPassword SNMP Authentication Password
* SNMP验证密码
*/
public void authNoPriv(final SNMPAuthProtocol authProtocol, final String authPassword) {
this.auth = SNMPAuthType.AUTH_NOPRIV;
this.authProtocol = authProtocol;
this.authPassword = authPassword;
}
/**
* Configure authentication information using authentication type: SNMPAuthType.AUTH_PRIV
* 设置身份验证信息,使用身份验证类型为:SNMPAuthType.AUTH_PRIV
*
* @param authProtocol SNMP Authentication Type
* SNMP验证类型
* @see org.nervousync.enumerations.snmp.auth.SNMPAuthProtocol
* @param authPassword SNMP Authentication Password
* SNMP验证密码
* @param privProtocol Type of encryption for the privacy password if authentication level is AUTH_PRIV
* 私有密码的加密方式,当验证类型为AUTH_PRIV时有效
* @see org.nervousync.enumerations.snmp.auth.SNMPPrivProtocol
* @param privPassword SNMP Private Password. The minimum length of the Priv Password must be eight characters.
* SNMP私有密码。密码长度必须大于等于8个字符
*/
public void authWithPriv(final SNMPAuthProtocol authProtocol, final String authPassword,
final SNMPPrivProtocol privProtocol, final String privPassword) {
this.auth = SNMPAuthType.AUTH_PRIV;
this.authProtocol = authProtocol;
this.authPassword = authPassword;
this.privProtocol = privProtocol;
this.privPassword = privPassword;
}
}