Skip to content

Commit fc72230

Browse files
author
Marcin Przepiorowski
committed
v2.4.4
2 parents c8d8566 + ffb2e10 commit fc72230

File tree

11 files changed

+344
-50
lines changed

11 files changed

+344
-50
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 2.4.4
2+
3+
### Added
4+
- [fix for #100](https://github.com/delphix/dxtoolkit/issues/100) - Request for new dxtoolkit command that can do port validation
5+
6+
### Changed
7+
- [fix for #105](https://github.com/delphix/dxtoolkit/issues/105) - dx_get_db_env: Get database name (the one in the instance) for SQL databases
8+
- [fix for #106](https://github.com/delphix/dxtoolkit/issues/106) - fix for db_get_db_env -hostenv and -config does not work together
9+
110
## 2.4.3
211

312
### Changed
@@ -22,8 +31,6 @@ Packages named with installer, requires the following steps:
2231
- [fix for #104](https://github.com/delphix/dxtoolkit/issues/104) - fix for vCDB and dx_get_db_env with -config
2332

2433

25-
26-
2734
## 2.4.1
2835

2936
Configuration files with an encrypted passwords created before version 2.4.0 has to be regenerated due

bin/dx_connection_check.pl

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
#
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
#
14+
# Copyright (c) 2019 by Delphix. All rights reserved.
15+
#
16+
# Program Name : dx_connection_check.pl
17+
# Description : Check if port is open
18+
# Author : Marcin Przepiorowski
19+
# Created : Dec 2019
20+
#
21+
#
22+
23+
use strict;
24+
use warnings;
25+
use JSON;
26+
use Getopt::Long qw(:config no_ignore_case no_auto_abbrev); #avoids conflicts with ex host and help
27+
use File::Basename;
28+
use Pod::Usage;
29+
use FindBin;
30+
use Data::Dumper;
31+
32+
my $abspath = $FindBin::Bin;
33+
34+
use lib '../lib';
35+
use Engine;
36+
use Formater;
37+
use Toolkit_helpers;
38+
use Host_obj;
39+
use Action_obj;
40+
41+
my $version = $Toolkit_helpers::version;
42+
43+
GetOptions(
44+
'help|?' => \(my $help),
45+
'd|engine=s' => \(my $dx_host),
46+
'hostip=s' => \(my $hostip),
47+
'port=i' => \(my $port),
48+
'debug:i' => \(my $debug),
49+
'dever=s' => \(my $dever),
50+
'all' => (\my $all),
51+
'version' => \(my $print_version),
52+
'configfile|c=s' => \(my $config_file)
53+
) or pod2usage(-verbose => 1, -input=>\*DATA);
54+
55+
pod2usage(-verbose => 2, -input=>\*DATA) && exit if $help;
56+
die "$version\n" if $print_version;
57+
58+
my $engine_obj = new Engine ($dever, $debug);
59+
$engine_obj->load_config($config_file);
60+
61+
if (defined($all) && defined($dx_host)) {
62+
print "Option all (-all) and engine (-d|engine) are mutually exclusive \n";
63+
pod2usage(-verbose => 1, -input=>\*DATA);
64+
exit (1);
65+
}
66+
67+
68+
if (! (defined($hostip) && defined($port) ) ) {
69+
print "Option hostip and port are required. \n";
70+
pod2usage(-verbose => 1, -input=>\*DATA);
71+
exit (1);
72+
}
73+
74+
# this array will have all engines to go through (if -d is specified it will be only one engine)
75+
my $engine_list = Toolkit_helpers::get_engine_list($all, $dx_host, $engine_obj);
76+
77+
78+
my %restore_state;
79+
80+
my $ret = 0;
81+
82+
83+
for my $engine ( sort (@{$engine_list}) ) {
84+
# main loop for all work
85+
if ($engine_obj->dlpx_connect($engine)) {
86+
print "Can't connect to Dephix Engine $dx_host\n\n";
87+
$ret = $ret + 1;
88+
next;
89+
};
90+
91+
my ($connfault, $reason) = $engine_obj->checkSSHconnectivity("dummy", "password", $hostip, $port);
92+
93+
if (version->parse($engine_obj->getApi()) >= version->parse(1.10.0)) {
94+
if ($connfault == 0) {
95+
print "Connection using SSH with dummy user and password is sucessful\n";
96+
next;
97+
}
98+
my $out = $reason->{"error"}->{"details"};
99+
if ($out =~ m/An error occurred when attempting/) {
100+
print "Connection to $hostip:$port refused - port closed\n";
101+
$ret = $ret + 1;
102+
} elsif ($out =~ m/Could not log into/) {
103+
print "Connection to $hostip:$port sucessful - port seems to be opened\n";
104+
} else {
105+
print "Engine responded with unknown state. Please check below:\n";
106+
print Dumper $reason->{"details"};
107+
print Dumper $reason->{"commandOutput"};
108+
$ret = $ret + 1;
109+
}
110+
111+
}
112+
113+
}
114+
115+
exit $ret;
116+
117+
118+
__DATA__
119+
120+
=head1 SYNOPSIS
121+
122+
dx_connection_check [ -engine|d <delphix identifier> | -all ] [ -configfile file ] -hostip IP/FQDN -port portno [ --help|? ] [ -debug ]
123+
124+
=head1 DESCRIPTION
125+
126+
Check connectivity between Delphix Engine and host using a specified port
127+
128+
=head1 ARGUMENTS
129+
130+
Delphix Engine selection - if not specified a default host(s) from dxtools.conf will be used.
131+
132+
=over 10
133+
134+
=item B<-engine|d>
135+
Specify Delphix Engine name from dxtools.conf file
136+
137+
=item B<-all>
138+
Run script on all engines
139+
140+
=item B<-hostip IP/FQDN>
141+
Host IP or FQDN
142+
143+
=item B<-port portno>
144+
Port to check
145+
146+
147+
=back
148+
149+
=head1 OPTIONS
150+
151+
=over 2
152+
153+
=item B<-help>
154+
Print this screen
155+
156+
=item B<-debug>
157+
Turn on debugging
158+
159+
=back
160+
161+
=head1 EXAMPLES
162+
163+
Check if listener port is open
164+
165+
dx_connection_check -d 53 -hostip 192.168.1.20 -port 1521
166+
Connection to 192.168.1.20:1521 refused - port closed
167+
168+
Check if ssh port is open
169+
170+
dx_connection_check -d 53 -hostip 192.168.1.20 -port 22
171+
Connection to 192.168.1.20:22 sucessful - port seems to be opened
172+
173+
=cut

bin/dx_get_db_env.pl

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353

5454
my $parentlast = 'p';
5555
my $hostenv = 'h';
56+
my $configtype = 's';
5657

5758
GetOptions(
5859
'help|?' => \(my $help),
@@ -73,6 +74,7 @@
7374
'parentlast=s' => \($parentlast),
7475
'hostenv=s' => \($hostenv),
7576
'config' => \(my $config),
77+
'configtype=s' => \($configtype),
7678
'backup=s' => \(my $backup),
7779
'olderthan=s' => \(my $creationtime),
7880
'save=s' => \(my $save),
@@ -173,19 +175,34 @@
173175
$primary = 1;
174176

175177
} elsif (defined($config)) {
176-
$hostenv = 'e';
177-
$output->addHeader(
178-
{'Appliance', 20},
179-
{'Env. name', 20},
180-
{'Database', 30},
181-
{'Group', 15},
182-
{'Type', 8},
183-
{'SourceDB', 30},
184-
{'Repository', 35},
185-
{'DB type', 10},
186-
{'Version', 10},
187-
{'Other', 100}
188-
);
178+
if ($configtype eq 's') {
179+
$hostenv = 'e';
180+
$output->addHeader(
181+
{'Appliance', 20},
182+
{'Env. name', 20},
183+
{'Database', 30},
184+
{'Group', 15},
185+
{'Type', 8},
186+
{'SourceDB', 30},
187+
{'Repository', 35},
188+
{'DB type', 10},
189+
{'Version', 10},
190+
{'Other', 100}
191+
);
192+
} elsif ($configtype eq 'd') {
193+
$output->addHeader(
194+
{'Appliance', 20},
195+
{$hostenv_head, 20},
196+
{'Database', 30},
197+
{'Group', 15},
198+
{'Type', 8},
199+
{'SourceDB', 30},
200+
{'Repository', 35},
201+
{'DB type', 10},
202+
{'Version', 15},
203+
{'Server DB name', 30}
204+
);
205+
}
189206
} else {
190207
if (defined($masking)) {
191208
$output->addHeader(
@@ -328,20 +345,35 @@
328345
my $groupname = $groups->getName($dbobj->getGroup());
329346

330347
if (defined($config)) {
331-
332-
my $other = $dbobj->getConfig($templates, undef, $groups);
333-
$output->addLine(
334-
$engine,
335-
$hostenv_line,
336-
$dbobj->getName(),
337-
$groupname,
338-
$dbobj->getType(),
339-
$parentname,
340-
$dbobj->getHome(),
341-
$dbobj->{_dbtype},
342-
$dbobj->getVersion(),
343-
$other
344-
);
348+
if ($configtype eq 's') {
349+
my $other = $dbobj->getConfig($templates, undef, $groups);
350+
$output->addLine(
351+
$engine,
352+
$hostenv_line,
353+
$dbobj->getName(),
354+
$groupname,
355+
$dbobj->getType(),
356+
$parentname,
357+
$dbobj->getHome(),
358+
$dbobj->{_dbtype},
359+
$dbobj->getVersion(),
360+
$other
361+
);
362+
} elsif ($configtype eq 'd') {
363+
my $other = $dbobj->getConfig($templates, undef, $groups);
364+
$output->addLine(
365+
$engine,
366+
$hostenv_line,
367+
$dbobj->getName(),
368+
$groupname,
369+
$dbobj->getType(),
370+
$parentname,
371+
$dbobj->getHome(),
372+
$dbobj->{_dbtype},
373+
$dbobj->getVersion(),
374+
$dbobj->getDatabaseName()
375+
);
376+
}
345377

346378
} elsif (defined($backup)) {
347379

@@ -410,6 +442,7 @@
410442
$maskedjob_name
411443
);
412444
} else {
445+
413446
$output->addLine(
414447
$engine,
415448
$hostenv_line,

bin/dx_set_envpass.pl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313
#
14-
# Copyright (c) 2016 by Delphix. All rights reserved.
14+
# Copyright (c) 2016,2019 by Delphix. All rights reserved.
1515
#
1616
# Program Name : dx_set_envpass.pl
1717
# Description : Set password for OS Delphix user or DB Delphix user
@@ -119,6 +119,7 @@
119119
my $hostref = $environments->getHost($envitem);
120120

121121
my $connfault = 0;
122+
my $result;
122123

123124
if ( $environments->getType($envitem) ne 'WindowsHostEnvironment' ) {
124125

@@ -131,18 +132,20 @@
131132
for my $clunode ( @{$cluhosts} ) {
132133

133134
my $nodeaddr = $hosts->getHostAddr($clunode->{host});
134-
$connfault = $connfault + $engine_obj->checkSSHconnectivity($username, $password, $nodeaddr);
135+
my $port = $hosts->getHostPort($clunode->{host});
136+
($connfault, $result) = $connfault + $engine_obj->checkSSHconnectivity($username, $password, $nodeaddr, $port);
135137

136138
}
137139
} else {
138140
my $nodeaddr = $hosts->getHostAddr($hostref);
139-
$connfault = $engine_obj->checkSSHconnectivity($username, $password, $nodeaddr);
141+
my $port = $hosts->getHostPort($hostref);
142+
($connfault, $result) = $engine_obj->checkSSHconnectivity($username, $password, $nodeaddr, $port);
140143
}
141144

142145
} else {
143146
if ( $hostref ne 'CLUSTER' ) {
144147
my $nodeaddr = $hosts->getHostAddr($hostref);
145-
$connfault = $engine_obj->checkConnectorconnectivity($username, $password, $nodeaddr);
148+
($connfault, $result) = $engine_obj->checkConnectorconnectivity($username, $password, $nodeaddr);
146149
}
147150

148151

0 commit comments

Comments
 (0)