enh(as400): add ssl connection option (#5476)

Co-authored-by: garnier-quentin <garnier.quentin@gmail.com>
This commit is contained in:
sdepassio 2025-03-05 17:25:13 +01:00 committed by GitHub
parent 5a23b681ec
commit baf703598e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
26 changed files with 135 additions and 56 deletions

View File

@ -6,9 +6,9 @@ RUN bash -e <<EOF
dnf install -y \
git \
java-17-openjdk-devel \
wget \
zstd \
java-17-openjdk-devel
zstd
cd /usr/local/src
wget https://dlcdn.apache.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.tar.gz

View File

@ -6,9 +6,9 @@ RUN bash -e <<EOF
dnf install -y \
git \
java-17-openjdk-devel \
wget \
zstd \
java-17-openjdk-devel
zstd
cd /usr/local/src
wget https://dlcdn.apache.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.tar.gz

View File

@ -8,9 +8,9 @@ apt-get update
apt-get install -y \
ca-certificates \
git \
zstd \
maven=3.8.7-1 \
openjdk-17-jdk
openjdk-17-jdk \
zstd
echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | tee /etc/apt/sources.list.d/goreleaser.list

View File

@ -8,9 +8,9 @@ apt-get update
apt-get install -y \
ca-certificates \
git \
zstd \
maven=3.6.3-5 \
openjdk-17-jdk
openjdk-17-jdk \
zstd
echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | tee /etc/apt/sources.list.d/goreleaser.list

View File

@ -8,9 +8,9 @@ apt-get update
apt-get install -y \
ca-certificates \
git \
openjdk-17-jdk \
wget \
zstd \
openjdk-17-jdk
zstd
cd /usr/local/src
wget https://dlcdn.apache.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.tar.gz

View File

@ -20,7 +20,7 @@ jobs:
get-environment:
uses: ./.github/workflows/get-environment.yml
with:
version_file: as400/packaging/centreon-as400-daemon.yaml
version_file: as400/connector.as400/pom.xml
package:
needs: [get-environment]

View File

@ -249,9 +249,11 @@ jobs:
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const { execSync } = require('child_process');
let version = '';
if ('${{ steps.get_stability.outputs.stability }}' === 'testing') {
if ('${{ inputs.version_file }}'.match(/pom\.xml$/)) {
version = execSync(`grep -m 1 "<version>.*</version>" ${{ inputs.version_file }} | sed 's/.*<version>\\(.*\\)<\\/version>.*/\\1/'`).toString().trim();
} else if ('${{ steps.get_stability.outputs.stability }}' === 'testing') {
const branchName = "${{ github.head_ref || github.ref_name }}";
const matches = branchName.match(/^(?:release|hotfix)-(\d{8})$/);
if (matches) {

View File

@ -26,6 +26,7 @@ import java.text.NumberFormat;
import java.util.Locale;
import com.ibm.as400.access.AS400;
import com.ibm.as400.access.SecureAS400;
import com.ibm.as400.access.AS400SecurityException;
import com.ibm.as400.access.ConnectionEvent;
import com.ibm.as400.access.ConnectionListener;
@ -44,11 +45,13 @@ public abstract class AbstractHandler {
protected String host = null;
protected String login = null;
protected String password = null;
protected Integer ssl = 0;
public AbstractHandler(final String host, final String login, final String password) {
public AbstractHandler(final String host, final String login, final String password, final Integer ssl) {
this.host = host;
this.login = login;
this.password = password;
this.ssl = ssl;
}
static {
@ -77,7 +80,28 @@ public abstract class AbstractHandler {
properties.setLoginTimeout(Conf.as400LoginTimeout);
properties.setSoTimeout(Conf.as400ReadTimeout);
final AS400 system = new AS400(this.host, this.login, this.password);
if (this.ssl == 1) {
SecureAS400 system = new SecureAS400(this.host, this.login, this.password);
system.setSocketProperties(properties);
system.addConnectionListener(new ConnectionListener() {
@Override
public void connected(final ConnectionEvent event) {
ConnectorLogger.getInstance().getLogger().debug("Connect event service : " + event.getService());
}
@Override
public void disconnected(final ConnectionEvent event) {
ConnectorLogger.getInstance().getLogger().debug("Disconnect event service : " + event.getService());
}
});
system.validateSignon();
return (AS400)system;
}
AS400 system = new AS400(this.host, this.login, this.password);
system.setSocketProperties(properties);
system.addConnectionListener(new ConnectionListener() {
@Override

View File

@ -34,8 +34,8 @@ import com.centreon.connector.as400.dispatcher.check.ResponseData;
*/
public class CommandHandler extends AbstractHandler implements ICommandHandler {
public CommandHandler(final String host, final String login, final String password) {
super(host, login, password);
public CommandHandler(final String host, final String login, final String password, final Integer ssl) {
super(host, login, password, ssl);
}
@Override

View File

@ -38,10 +38,10 @@ public class DiskHandler extends AbstractHandler implements IDiskHandler {
private QyaspolYasp0300PcmlHandler qyaspolPcmlHandler = null;
public DiskHandler(final String host, final String login, final String password)
public DiskHandler(final String host, final String login, final String password, final Integer ssl)
throws AS400SecurityException, IOException {
super(host, login, password);
this.qyaspolPcmlHandler = new QyaspolYasp0300PcmlHandler(host, login, password);
super(host, login, password, ssl);
this.qyaspolPcmlHandler = new QyaspolYasp0300PcmlHandler(host, login, password, ssl);
}
@Override

View File

@ -37,8 +37,8 @@ import com.centreon.connector.as400.dispatcher.check.ResponseData;
public class JobHandler extends AbstractHandler implements IJobHandler {
private final JobCache jobCache;
public JobHandler(final String host, final String login, final String password) {
super(host, login, password);
public JobHandler(final String host, final String login, final String password, final Integer ssl) {
super(host, login, password, ssl);
this.jobCache = new JobCache(this);
}

View File

@ -37,8 +37,8 @@ import com.centreon.connector.as400.dispatcher.check.ResponseData;
*/
public class JobQueueHandler extends AbstractHandler implements IJobQueueHandler {
public JobQueueHandler(final String host, final String login, final String password) {
super(host, login, password);
public JobQueueHandler(final String host, final String login, final String password, final Integer ssl) {
super(host, login, password, ssl);
}
@Override

View File

@ -42,9 +42,9 @@ import com.centreon.connector.as400.dispatcher.check.ResponseData;
*/
public class SubSystemHandler extends AbstractHandler implements ISubSystemHandler {
public SubSystemHandler(final String host, final String login, final String password)
public SubSystemHandler(final String host, final String login, final String password, final Integer ssl)
throws AS400SecurityException, IOException {
super(host, login, password);
super(host, login, password, ssl);
}
@Override

View File

@ -45,14 +45,14 @@ import com.centreon.connector.as400.dispatcher.check.ResponseData;
public class SystemHandler extends AbstractHandler implements ISystemHandler {
private SystemStatus status = null;
public SystemHandler(final String host, final String login, final String password)
public SystemHandler(final String host, final String login, final String password, final Integer ssl)
throws AS400SecurityException, IOException {
this(host, login, password, null);
this(host, login, password, null, ssl);
}
public SystemHandler(final String host, final String login, final String password, SystemStatus as400Status)
public SystemHandler(final String host, final String login, final String password, SystemStatus as400Status, final Integer ssl)
throws AS400SecurityException, IOException {
super(host, login, password);
super(host, login, password, ssl);
this.status = as400Status == null ? new SystemStatus(getNewAs400()) : as400Status;
}

View File

@ -26,6 +26,7 @@ import java.util.LinkedList;
import java.util.List;
import com.ibm.as400.access.AS400;
import com.ibm.as400.access.SecureAS400;
import com.ibm.as400.access.AS400Message;
import com.ibm.as400.access.AS400SecurityException;
import com.ibm.as400.access.ConnectionEvent;
@ -61,11 +62,13 @@ public class QyaspolYasp0300PcmlHandler {
String host = null;
String login = null;
String password = null;
Integer ssl = 0;
public QyaspolYasp0300PcmlHandler(final String host, final String login, final String password) {
public QyaspolYasp0300PcmlHandler(final String host, final String login, final String password, final Integer ssl) {
this.host = host;
this.login = login;
this.password = password;
this.ssl = ssl;
}
public void addYasp0300Data(final Yasp0300Data data) {
@ -238,7 +241,27 @@ public class QyaspolYasp0300PcmlHandler {
properties.setLoginTimeout(Conf.as400LoginTimeout);
properties.setSoTimeout(Conf.as400ReadTimeout);
final AS400 system = new AS400(this.host, this.login, this.password);
if (this.ssl == 1) {
SecureAS400 system = new SecureAS400(this.host, this.login, this.password);
system.setSocketProperties(properties);
system.addConnectionListener(new ConnectionListener() {
@Override
public void connected(final ConnectionEvent event) {
ConnectorLogger.getInstance().getLogger().debug("Connect event service : " + event.getService());
}
@Override
public void disconnected(final ConnectionEvent event) {
ConnectorLogger.getInstance().getLogger().debug("Disconnect event service : " + event.getService());
}
});
system.validateSignon();
return (AS400)system;
}
AS400 system = new AS400(this.host, this.login, this.password);
system.setSocketProperties(properties);
system.addConnectionListener(new ConnectionListener() {
@Override

View File

@ -102,8 +102,8 @@ public class CachedMessageQueueHandler extends AbstractHandler implements ICache
return sb.toString();
}
public CachedMessageQueueHandler(final String host, final String login, final String password) {
super(host, login, password);
public CachedMessageQueueHandler(final String host, final String login, final String password, final Integer ssl) {
super(host, login, password, ssl);
}
@Override

View File

@ -42,8 +42,8 @@ import com.centreon.connector.as400.dispatcher.check.ResponseData;
*/
public class MessageQueueHandler extends AbstractHandler implements IMessageQueueHandler {
public MessageQueueHandler(final String host, final String login, final String password) {
super(host, login, password);
public MessageQueueHandler(final String host, final String login, final String password, final Integer ssl) {
super(host, login, password, ssl);
}
@Override

View File

@ -69,8 +69,8 @@ public class WorkWithProblemHandler extends AbstractHandler {
private final boolean SSL = false;
private final String logPrefix;
public WorkWithProblemHandler(final String host, final String login, final String password) {
super(host, login, password);
public WorkWithProblemHandler(final String host, final String login, final String password, final Integer ssl) {
super(host, login, password, ssl);
this.logPrefix = "[" + WorkWithProblemHandler.INSTANCE_ID++ + "]";
}

View File

@ -40,5 +40,7 @@ public interface IClient {
String getAs400CheckType();
Integer getAs400Ssl();
Object getAs400Arg(String key);
}

View File

@ -42,6 +42,7 @@ abstract class AbstractClient implements IClient {
private String as400Password = null;
private String as400CheckType = null;
private String as400Args = null;
private Integer as400Ssl = 0;
private List<Map<String, String>> argList = new ArrayList<Map<String, String>>();
@Override
@ -77,6 +78,11 @@ abstract class AbstractClient implements IClient {
return this.input.getArg(key);
}
@Override
public Integer getAs400Ssl() {
return this.input.getSsl();
}
public List<Map<String , String>> getAs400ArgList(String key) {
Object arg = this.input.getArg(key);
if (arg == null) {

View File

@ -87,6 +87,7 @@ public class CheckDispatcher {
private String host = null;
private String login = null;
private String password = null;
private Integer ssl = 0;
private volatile ConcurrentHashMap<String, Long> filter = new ConcurrentHashMap<String, Long>();
@ -135,10 +136,11 @@ public class CheckDispatcher {
}
}
public CheckDispatcher(final String host, final String login, final String password) {
public CheckDispatcher(final String host, final String login, final String password, final Integer ssl) {
this.host = host;
this.login = login;
this.password = password;
this.ssl = ssl;
this.executorGlobal = new ThreadPoolExecutorPostFilter(5, 10, Conf.workerQueueTimeout, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>());
@ -165,6 +167,10 @@ public class CheckDispatcher {
return this.password;
}
public Integer getSsl() {
return this.ssl;
}
public synchronized void dispatch(final NetworkClient client) {
if (this.filter.containsKey(client.getRawRequest())) {
@ -190,52 +196,52 @@ public class CheckDispatcher {
public ICommandHandler getCommandHandler() throws AS400SecurityException, IOException {
if (this.commandHandler == null) {
this.commandHandler = new CommandHandler(this.host, this.login, this.password);
this.commandHandler = new CommandHandler(this.host, this.login, this.password, this.ssl);
}
return this.commandHandler;
}
public IDiskHandler getDiskHandler() throws AS400SecurityException, IOException {
if (this.diskHandler == null) {
this.diskHandler = new DiskHandler(this.host, this.login, this.password);
this.diskHandler = new DiskHandler(this.host, this.login, this.password, this.ssl);
}
return this.diskHandler;
}
public IJobHandler getJobHandler() throws AS400SecurityException, IOException {
if (this.jobHandler == null) {
this.jobHandler = new JobHandler(this.host, this.login, this.password);
this.jobHandler = new JobHandler(this.host, this.login, this.password, this.ssl);
}
return this.jobHandler;
}
public ISubSystemHandler getSubSystemHandler() throws AS400SecurityException, IOException {
if (this.subSystemHandler == null) {
this.subSystemHandler = new SubSystemHandler(this.host, this.login, this.password);
this.subSystemHandler = new SubSystemHandler(this.host, this.login, this.password, this.ssl);
}
return this.subSystemHandler;
}
public ISystemHandler getSystemHandler() throws AS400SecurityException, IOException {
if (this.systemHandler == null) {
this.systemHandler = new SystemHandler(this.host, this.login, this.password);
this.systemHandler = new SystemHandler(this.host, this.login, this.password, this.ssl);
}
return this.systemHandler;
}
public ICachedMessageQueueHandler getCachedMessageQueueHandler() throws AS400SecurityException, IOException {
return new CachedMessageQueueHandler(this.host, this.login, this.password);
return new CachedMessageQueueHandler(this.host, this.login, this.password, this.ssl);
}
public IMessageQueueHandler getMessageQueueHandler() throws AS400SecurityException, IOException {
return new MessageQueueHandler(this.host, this.login, this.password);
return new MessageQueueHandler(this.host, this.login, this.password, this.ssl);
}
public IJobQueueHandler getJobQueueHandler() throws AS400SecurityException, IOException {
return new JobQueueHandler(this.host, this.login, this.password);
return new JobQueueHandler(this.host, this.login, this.password, this.ssl);
}
public WorkWithProblemHandler getWrkPrbHandler() throws AS400SecurityException, IOException {
return new WorkWithProblemHandler(this.host, this.login, this.password);
return new WorkWithProblemHandler(this.host, this.login, this.password, this.ssl);
}
}

View File

@ -31,6 +31,7 @@ public class InputData {
private String password = null;
private String host = null;
private String command = null;
private Integer ssl = null;
Map<String, Object> args = null;
public InputData() {
@ -44,6 +45,13 @@ public class InputData {
return this.password;
}
public Integer getSsl() {
if (this.ssl == null || this.ssl == 0) {
return 0;
}
return 1;
}
public String getHost() {
return this.host;
}

View File

@ -52,37 +52,37 @@ public class ClientDispatcherImpl implements ClientDispatcher {
}
private synchronized CheckDispatcher createNewCheckDispatcher(final String host, final String login,
final String password) throws AS400SecurityException, IOException, DelayedConnectionException, Exception {
final String password, final Integer ssl) throws AS400SecurityException, IOException, DelayedConnectionException, Exception {
ConnectorLogger.getInstance().info("create new As400 : " + host);
CheckDispatcher resource = null;
resource = new CheckDispatcher(host, login, password);
resource = new CheckDispatcher(host, login, password, ssl);
this.pool.put(resource, System.currentTimeMillis());
return resource;
}
private CheckDispatcher getAs400(final String host, final String login, final String password)
private CheckDispatcher getAs400(final String host, final String login, final String password, final Integer ssl)
throws AS400SecurityException, IOException, DelayedConnectionException, Exception {
for (final CheckDispatcher resource : this.pool.keySet()) {
if (resource.getHost().equalsIgnoreCase(host) && resource.getLogin().equalsIgnoreCase(login)
&& resource.getPassword().equalsIgnoreCase(password)) {
&& resource.getPassword().equalsIgnoreCase(password) && resource.getSsl() == ssl) {
this.pool.put(resource, System.currentTimeMillis());
return resource;
}
}
return this.createNewCheckDispatcher(host, login, password);
return this.createNewCheckDispatcher(host, login, password, ssl);
}
@Override
public synchronized void dispatch(final NetworkClient client)
throws AS400SecurityException, IOException, DelayedConnectionException, Exception {
final CheckDispatcher checkDispatcher = this.getAs400(client.getAs400Host(), client.getAs400Login(),
client.getAs400Password());
client.getAs400Password(), client.getAs400Ssl());
checkDispatcher.dispatch(client);
}
}

View File

@ -35,7 +35,7 @@ public class SystemHandlerTest {
try {
SystemStatus as400 = mock(SystemStatus.class);
when(as400.getSystemPools()).thenReturn(new Vector<Object>().elements());
SystemHandler sh = new SystemHandler(null, null, null, as400);
SystemHandler sh = new SystemHandler(null, null, null, as400, null);
sh.dumpSystem();
} finally {
System.setOut(originalOut);

View File

@ -53,7 +53,8 @@ sub new {
'critical-http-status:s' => { name => 'critical_http_status' },
'as400-hostname:s' => { name => 'as400_hostname' },
'as400-username:s' => { name => 'as400_username' },
'as400-password:s' => { name => 'as400_password' }
'as400-password:s' => { name => 'as400_password' },
'as400-ssl' => { name => 'as400_ssl' }
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1);
@ -87,6 +88,7 @@ sub check_options {
$self->{as400_hostname} = (defined($self->{option_results}->{as400_hostname})) ? $self->{option_results}->{as400_hostname} : '';
$self->{as400_username} = (defined($self->{option_results}->{as400_username})) ? $self->{option_results}->{as400_username} : '';
$self->{as400_password} = (defined($self->{option_results}->{as400_password})) ? $self->{option_results}->{as400_password} : '';
$self->{as400_ssl} = (defined($self->{option_results}->{as400_ssl})) ? 1 : 0;
if ($self->{connector_hostname} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --connector-hostname option.");
@ -152,6 +154,7 @@ sub request_api {
host => $self->{as400_hostname},
login => $self->{as400_username},
password => $self->{as400_password},
ssl => $self->{as400_ssl},
command => $options{command}
};
if (defined($options{args})) {
@ -247,6 +250,10 @@ AS/400 username (required)
AS/400 password (required)
=item B<--as400-ssl>
Use SSL connection (port: 9475)
=back
=head1 DESCRIPTION

View File

@ -24,6 +24,7 @@ api.meraki.com
--api-username
--api-version
AppearTV
AS400
ASAM
Avigilon
Avocent