Skip to content

Commit

Permalink
puppeteer: just try if node script works
Browse files Browse the repository at this point in the history
and print error if it fails.
  • Loading branch information
sni committed May 28, 2023
1 parent 2c8ff31 commit d7262fd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .ci/prepare_machine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ apt-get -y install \
libconfig-general-perl \
libwww-mechanize-perl \
chromium-browser \
npm \

echo "deb http://labs.consol.de/repo/stable/ubuntu $(lsb_release -cs) main" >> /etc/apt/sources.list
wget -q "http://labs.consol.de/repo/stable/RPM-GPG-KEY" -O - | apt-key add -
Expand All @@ -83,6 +84,8 @@ else
:
fi

npm i -g puppeteer

# ensure we have a test database in place for tests
/etc/init.d/mysql start
mysql -e "create database IF NOT EXISTS test;" -uroot -proot
Expand Down
14 changes: 5 additions & 9 deletions plugins/plugins-available/reports2/lib/Thruk/Utils/Reports.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1764,20 +1764,16 @@ sub _convert_to_pdf {
_debug("converting to pdf: ".$cmd);
my $out = Thruk::Utils::IO::cmd($cmd.' 2>&1');

# try again to avoid occasionally qt errors
if(!-e $attachment.'.pdf') {
my $error = Thruk::Utils::IO::read($logfile);
if($error eq "") { $error = $out; }
if($error =~ m/QPainter::begin/mx) {
$out = Thruk::Utils::IO::cmd($cmd);
}
if($error eq "") {
$error = "failed to produce a pdf file without any error message.\npwd: ".Cwd::getcwd()."\ncmdline:\n$cmd";
}
if(!-e $attachment.'.pdf') {
if($error =~ m/internal\/modules\/cjs\/loader\.js/mx) {
$error =~ s/^internal\/modules\/cjs\/loader\.js:\d+\s*throw\s*err;\s*\^\s*Error:/Node Error:/sgmx; # remove useless info from node errors
Thruk::Utils::IO::write($logfile, $error);
} else {
Thruk::Utils::IO::write($logfile, $error, undef, 1) unless -s $logfile;
die('report failed: '.$error);
}
die('report failed: '.$error);
}

move($attachment.'.pdf', $attachment) or die('move '.$attachment.'.pdf to '.$attachment.' failed: '.$!);
Expand Down
17 changes: 6 additions & 11 deletions script/grafana_export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,10 @@ if [ -n "$OMD_ROOT" ]; then
export NODE_PATH=$OMD_ROOT/lib/node_modules/
fi
fi
if [ -n "$NODE_PATH" ] && [ -d "$NODE_PATH" ]; then
node $DIR/puppeteer.js "$INPUT" "${TEMPFILE}.png" "$WIDTH" "$HEIGHT" "$THRUK_SESSION_ID" 2>&1
rc=$?
if [ -e "$TEMPFILE.png" ]; then
mv "$TEMPFILE.png" "$TEMPFILE"
fi
exit $rc
fi

echo "ERROR: puppeteer not found"
echo "(phantomjs is no longer support and required)"
exit 1
node $DIR/puppeteer.js "$INPUT" "${TEMPFILE}.png" "$WIDTH" "$HEIGHT" "$THRUK_SESSION_ID" 2>&1
rc=$?
if [ -e "$TEMPFILE.png" ]; then
mv "$TEMPFILE.png" "$TEMPFILE"
fi
exit $rc
13 changes: 4 additions & 9 deletions script/html2pdf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,8 @@ if [ -n "$OMD_ROOT" ]; then
export NODE_PATH=$OMD_ROOT/lib/node_modules/
fi
fi
if [ -n "$NODE_PATH" ] && [ -d "$NODE_PATH" ]; then
node $DIR/puppeteer.js "$INPUT" "${OUTPUT}.pdf" "1600" "1200" "" $IS_REPORT 2>&1
mv "${OUTPUT}.pdf" "${OUTPUT}"
rc=$?
exit $rc
fi

echo "ERROR: puppeteer not found"
echo "(phantomjs is no longer support and required)"
exit 1
node $DIR/puppeteer.js "$INPUT" "${OUTPUT}.pdf" "1600" "1200" "" $IS_REPORT 2>&1
mv "${OUTPUT}.pdf" "${OUTPUT}"
rc=$?
exit $rc

0 comments on commit d7262fd

Please sign in to comment.