5 use Test::More tests => 5;
8 use_ok( 'OpenSRF::Utils::Config' );
9 use_ok( 'UNIVERSAL::require' );
10 use_ok( 'Getopt::Long' );
11 use_ok( 'Net::Domain' );
17 my ($gather, $hostname, $core_config, $tmpdir) =
18 (0, Net::Domain::hostfqdn(), '/openils/conf/opensrf_core.xml', '/tmp/');
22 'hostname=s' => \$hostname,
23 'config_file=s' => \$core_config,
24 'tempdir=s' => \$tmpdir,
27 while (my $mod = <DATA>) {
29 my @list = split / /, $mod;
35 my $version = $m->VERSION;
36 print "$m version $version\n" if ($version);
42 warn "Please install $mod\n";
43 $perloutput .= "Please install the $mod Perl module.\n";
45 warn "Please install one of the following modules: $mod\n";
46 $perloutput .= "Please install one of the following modules: $mod\n";
52 use OpenSRF::Transport::SlimJabber::Client;
53 use OpenSRF::Utils::SettingsParser;
54 use OpenSRF::Utils::SettingsClient;
58 (my $conf_dir = $core_config) =~ s#(.*)/.*#$1#;
59 OpenSRF::Utils::Config->load(config_file => $core_config);
60 my $conf = OpenSRF::Utils::Config->current;
61 my $settings_config = $conf->bootstrap->settings_config;
62 my $logfile = $conf->bootstrap->logfile;
63 (my $log_dir = $logfile) =~ s#(.*)/.*#$1#;
65 my $xmlparser = XML::LibXML->new();
66 my $confxml = $xmlparser->parse_file($core_config);
67 my $confxpc = XML::LibXML::XPathContext->new($confxml);
69 foreach my $section (qw/opensrf gateway/) {
70 my $j_username = $confxpc->find("/config/$section/username");
71 my $j_password = $confxpc->find("/config/$section/passwd");
72 my $j_port = $confxpc->find("/config/$section/port");
73 # We should check for a domains element to catch likely upgrade errors
74 my $j_domain = $confxpc->find("/config/$section/domain");
75 check_jabber($j_username, $j_password, $j_domain, $j_port);
78 my @routers = $confxpc->findnodes("/config/routers/router");
79 foreach my $router (@routers) {
80 my $j_username = $router->findvalue("./transport/username");
81 my $j_password = $router->findvalue("./transport/password");
82 my $j_port = $router->findvalue("./transport/port");
83 # We should check for a domains element to catch likely upgrade errors
84 my $j_domain = $router->findvalue("./transport/server");
85 check_jabber($j_username, $j_password, $j_domain, $j_port);
88 my $osrfxml = $xmlparser->parse_file($settings_config);
89 print "\nChecking database connections\n";
90 # Check database connections
91 my @databases = $osrfxml->findnodes('//database');
93 # If we have no database connections, this is probably the OpenSRF version
96 my $de = "* WARNING: There are no database connections defined in " .
97 "opensrf.xml. These are defined in services such as " .
98 "open-ils.cstore and open-ils.reporter. Please ensure that " .
99 "your opensrf_core.xml and opensrf.xml configuration files " .
100 "are based on the examples shipped with Evergreen instead of " .
106 foreach my $database (@databases) {
107 my $db_name = $database->findvalue("./db");
109 $db_name = $database->findvalue("./name");
111 my $db_host = $database->findvalue("./host");
112 my $db_port = $database->findvalue("./port");
113 my $db_user = $database->findvalue("./user");
114 my $db_pw = $database->findvalue("./pw");
115 if (!$db_pw && $database->parentNode->parentNode->nodeName eq 'reporter') {
116 $db_pw = $database->findvalue("./password");
118 my $de = "* WARNING: Deprecated <password> element used for the " .
119 "<reporter> entry. Please use <pw> instead.\n";
126 foreach my $node ($database->findnodes("ancestor::node()")) {
127 next unless $node->nodeType == XML::LibXML::XML_ELEMENT_NODE;
128 $osrf_xpath .= "/" . $node->nodeName;
130 $output .= test_db_connect($db_name, $db_host, $db_port, $db_user, $db_pw, $osrf_xpath);
133 print "\nChecking postgresql version\n";
134 system ("psql", "--version");
136 print "\nChecking database drivers to ensure <driver> matches <language>\n";
137 # Check database drivers
138 # if language eq 'C', driver eq 'pgsql'
139 # if language eq 'perl', driver eq 'Pg'
140 my @drivers = $osrfxml->findnodes('//driver');
141 foreach my $driver_node (@drivers) {
144 my @driver_xpath_nodes;
145 foreach my $node ($driver_node->findnodes("ancestor::node()")) {
146 next unless $node->nodeType == XML::LibXML::XML_ELEMENT_NODE;
147 $driver_xpath .= "/" . $node->nodeName;
148 push @driver_xpath_nodes, $node->nodeName;
151 my $driver = $driver_node->findvalue("child::text()");
152 while (pop(@driver_xpath_nodes) && scalar(@driver_xpath_nodes) > 0 && !$language) {
153 $lang_xpath = "/" . join('/', @driver_xpath_nodes) . "/language";
154 my @lang_nodes = $osrfxml->findnodes($lang_xpath);
155 next unless scalar(@lang_nodes > 0);
156 $language = $lang_nodes[0]->findvalue("child::text()");
158 if ($driver eq "pgsql") {
159 if ($driver_xpath =~ m#/reporter/#) {
160 $result = "* ERROR: reporter application must use driver 'Pg', but '$driver' is defined\n";
162 } elsif ($language eq "C") {
163 $result = "* OK: $driver language is $language in $lang_xpath\n";
165 $result = "* ERROR: $driver language is $language in $lang_xpath\n";
168 } elsif ($driver eq "Pg") {
169 if ($driver_xpath =~ m#/reporter/#) {
170 $result = "* OK: $driver language is undefined for reporter base configuration\n";
171 } elsif ($language eq "perl") {
172 $result = "* OK: $driver language is $language in $lang_xpath\n";
174 $result = "* ERROR: $driver language is $language in $lang_xpath\n";
178 } elsif ($driver eq "SIP") {
179 $result = "* OK SIP from telephony section. \n";
182 $result = "* ERROR: Unknown driver $driver in $driver_xpath\n";
189 print "\nChecking libdbi and libdbi-drivers\n";
190 $output .= check_libdbd();
192 print "\nChecking hostname\n";
193 my @hosts = $osrfxml->findnodes('/opensrf/hosts/*');
194 foreach my $host (@hosts) {
195 next unless $host->nodeType == XML::LibXML::XML_ELEMENT_NODE;
196 my $osrfhost = $host->nodeName;
198 if ($osrfhost ne $hostname && $osrfhost ne "localhost") {
199 $result = " * ERROR: expected hostname '$hostname', found '$osrfhost' in <hosts> section of opensrf.xml\n";
202 } elsif ($osrfhost eq "localhost") {
203 $result = " * OK: found hostname 'localhost' in <hosts> section of opensrf.xml\n";
205 $result = " * OK: found hostname '$hostname' in <hosts> section of opensrf.xml\n";
207 print $result unless $he;
211 # Check for oils_web.xml, required for acquisitions and many administration
212 # interfaces as of Evergreen 1.6
213 if (!-T '/openils/conf/oils_web.xml') {
214 my $de = "* WARNING: As of Evergreen 1.6, /openils/conf/oils_web.xml " .
215 "is a required configuration file. Copying " .
216 "/openils/conf/oils_web.xml.example should resolve this " .
224 get_debug_info( $tmpdir, $log_dir, $conf_dir, $perloutput, $output );
227 sub test_db_connect {
228 my ($db_name, $db_host, $db_port, $db_user, $db_pw, $osrf_xpath) = @_;
230 my $dsn = "dbi:Pg:dbname=$db_name;host=$db_host;port=$db_port";
232 my ($dbh, $encoding, $langs);
233 $dbh = DBI->connect($dsn, $db_user, $db_pw);
235 # Short-circuit if we didn't connect successfully
237 $de = "* $osrf_xpath :: Unable to connect to database $dsn, user=$db_user, password=$db_pw\n";
238 warn "* $osrf_xpath :: Unable to connect to database $dsn, user=$db_user, password=$db_pw\n";
242 # Get server encoding
243 my $sth = $dbh->prepare("SHOW server_encoding");
245 $sth->bind_col(1, \$encoding);
249 # Get list of server languages
250 $sth = $dbh->prepare("SELECT lanname FROM pg_catalog.pg_language");
252 $langs = $sth->fetchall_arrayref([0]);
256 print "* $osrf_xpath :: Successfully connected to database $dsn\n" unless ($de);
259 if ($encoding !~ m/(utf-?8|unicode)/i) {
260 $de .= "* ERROR: $osrf_xpath :: Database $dsn has encoding $encoding instead of UTF8 or UNICODE.\n";
261 warn "* ERROR: $osrf_xpath :: Database $dsn has encoding $encoding instead of UTF8 or UNICODE.\n";
263 print " * Database has the expected server encoding $encoding.\n";
266 my $result = check_db_langs($langs);
272 return ($de) ? $de : "* $osrf_xpath :: Successfully connected to database $dsn with encoding $encoding\n";
281 # Ensure the following PostgreSQL languages have been enabled
288 foreach my $lang (@$langs) {
289 my $lower = lc($$lang[0]);
290 $languages{$lower} = 1;
293 foreach my $lang (keys %languages) {
294 if (!$languages{$lang}) {
295 $errors .= " * ERROR: Language '$lang' is not enabled in the target database\n";
303 my ($j_username, $j_password, $j_domain, $j_port) = @_;
304 print "\nChecking Jabber connection for user $j_username, domain $j_domain\n";
307 my $client = OpenSRF::Transport::SlimJabber::Client->new(
309 username => $j_username,
310 password => $j_password,
312 resource => 'test123'
318 unless($client->initialize()) {
319 $je = "* Unable to connect to jabber server $j_domain\n";
320 warn "* Unable to connect to jabber server $j_domain\n";
323 $je = "* Error connecting to jabber:\n" . shift() . "\n";
324 warn "* Error connecting to jabber:\n" . shift() . "\n";
327 print "* Jabber successfully connected\n" unless ($je);
328 $output .= ($je) ? $je : "* Jabber successfully connected\n";
333 my @location = `/sbin/ldconfig --print | grep libdbdpgsql`; # simple(ton) attempt to filter out build versions
335 # This is pretty distro-specific, but let's worry about other distros and operating systems when we get there
336 my $res = "libdbi PostgreSQL driver not found in shared library path;
337 you may need to edit /etc/ld.so.conf or add an entry to /etc/ld.so.conf.d/
338 and run 'ldconfig' as root\n";
342 if ($location[0] !~ m#/usr/local/lib/dbd/#) {
343 my $res = "libdbdpgsql.so was not found in /usr/local/libdbi/dbd/
344 We have found that system packages don't link against libdbi.so;
345 therefore, we strongly recommend compiling libdbi and libdbi-drivers from source.\n";
349 if ($results eq '') {
350 $results = " * OK - found locally installed libdbi.so and libdbdpgsql.so in shared library path\n";
357 my $temp_dir = shift; # place we can write files
358 my $log = shift; # location of the log directory
359 my $config = shift; # location of the config files
360 my $perl_test = shift; # output from the Perl prereq testing
361 my $config_test = shift; # output from the config file testing
363 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
364 my $oils_time = sprintf("%04d-%02d-%02d_%02dh-%02d-%02d", $year+1900, $mon, $mday, $hour, $min, $sec);
366 # evil approach that requires no other Perl dependencies
368 my $oils_debug_dir = "$temp_dir/oils_$oils_time";
370 # Replace with something Perlish
371 mkdir($oils_debug_dir) or die $!;
373 # Replace with File::Copy
374 system("cp $log/*log $oils_debug_dir");
376 # Passwords will go through in the clear for now
377 system("cp $config/*xml $oils_debug_dir");
380 open(FH, ">", "$oils_debug_dir/perl_test.out") or die $!;
385 open(FH, ">", "$oils_debug_dir/xml_test.out") or die $!;
386 print FH $config_test;
389 # Tar this up - does any system not have tar?
390 system("tar czf oils_$oils_time.tar.gz oils_$oils_time");
392 # Clean up after ourselves, somewhat dangerously
393 system("rm -fr $oils_debug_dir");
395 print "Wrote your debug information to $temp_dir/oils_$oils_time.tar.gz.\n";
401 XML::LibXML::XPathContext
406 Class::DBI::AbstractSearch
409 Net::Z3950 Net::Z3950::ZOOM
417 DateTime::Format::ISO8601
418 DateTime::Format::Mail
421 JavaScript::SpiderMonkey
426 Spreadsheet::WriteExcel::Big
432 Business::CreditCard::Object
433 Net::Z3950::Simple2ZOOM