Skip to content

Commit

Permalink
deprecate phantomjs and use puppeteer for all pdf/png exports
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Nierlein <[email protected]>
  • Loading branch information
sni committed May 24, 2023
1 parent 99e0033 commit 2c8ff31
Show file tree
Hide file tree
Showing 26 changed files with 187 additions and 374 deletions.
1 change: 0 additions & 1 deletion .ci/prepare_machine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ apt-get -y install \
perl-doc \
libperl-dev \
cpanminus \
phantomjs \
tofrodos \
apache2 \
apache2-utils \
Expand Down
1 change: 0 additions & 1 deletion MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,6 @@ script/disable_debug_timer.sh
script/enable_debug_timer.sh
script/generate_timeperiod_transitions.pl
script/grafana_export.sh
script/html2pdf.js
script/html2pdf.sh
script/Makefile.thruk
script/nagexp
Expand Down
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Description: Monitoring Webinterface for Nagios/Icinga and Shinken

Package: thruk-plugin-reporting
Architecture: any
Depends: ${misc:Depends}, ${perl:Depends}, ${shlibs:Depends}, phantomjs,
Depends: ${misc:Depends}, ${perl:Depends}, ${shlibs:Depends},
thruk-base (= ${source:Version}), fonts-liberation
Description: This package contains the reporting addon for thruk useful for sla
and event reporting.
25 changes: 2 additions & 23 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ PERLVER=$(shell perl -e 'use Config; print $$Config{version}')
HTTPDCONF=$(shell if [ -d "/etc/apache2/conf-available" ]; then echo "/etc/apache2/conf-available"; else echo "/etc/apache2/conf.d"; fi )
SHELL=bash
export PERL5LIB=/usr/lib/thruk/perl5:/usr/lib64/thruk/perl5
FIXPHANTOMJS=$(shell if [ -f script/phantomjs ]; then echo "fix_phantomjs_location"; else echo ""; fi )

override_dh_auto_configure:
dh_auto_configure -- --prefix=/usr \
Expand All @@ -33,39 +32,19 @@ override_dh_auto_configure:
test -f themes/themes-available/Light/stylesheets/Light.css || make themes
test -f themes/themes-available/Light/stylesheets/Light.css || exit 1

override_dh_auto_install: local_auto_install $(FIXPHANTOMJS)
override_dh_auto_install: local_auto_install

local_auto_install:
dh_auto_install
# enable su logrotate, available since ubuntu 13.04 and debian 6
sed -i -e 's/^.*#su/ su/' debian/tmp/etc/logrotate.d/thruk-base
test -f debian/tmp/usr/share/thruk/root/thruk/cache/thruk-panorama-*.js || exit 1

fix_phantomjs_location:
# fix location of phantomjs
mkdir -p debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/thruk
mv debian/tmp/usr/share/thruk/script/phantomjs debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/thruk/
sed -e 's|/usr/share/thruk/script/phantomjs|/usr/lib/'$(DEB_HOST_MULTIARCH)'/thruk/phantomjs|' \
-i debian/tmp/etc/thruk/thruk.conf
echo "/usr/lib/$(DEB_HOST_MULTIARCH)/thruk/phantomjs" >> debian/thruk-plugin-reporting.install
echo "thruk-plugin-reporting: embedded-library usr/lib/$(DEB_HOST_MULTIARCH)/thruk/phantomjs: sqlite" >> debian/thruk-plugin-reporting.lintian-overrides
echo "thruk-plugin-reporting: embedded-library usr/lib/$(DEB_HOST_MULTIARCH)/thruk/phantomjs: libpng" >> debian/thruk-plugin-reporting.lintian-overrides
echo "thruk-plugin-reporting: embedded-library usr/lib/$(DEB_HOST_MULTIARCH)/thruk/phantomjs: zlib" >> debian/thruk-plugin-reporting.lintian-overrides
echo "thruk-plugin-reporting: embedded-library usr/lib/$(DEB_HOST_MULTIARCH)/thruk/phantomjs: libjpeg" >> debian/thruk-plugin-reporting.lintian-overrides
echo "thruk-plugin-reporting: embedded-library usr/lib/$(DEB_HOST_MULTIARCH)/thruk/phantomjs: openssl" >> debian/thruk-plugin-reporting.lintian-overrides
echo "thruk-plugin-reporting: embedded-library libjpeg usr/lib/$(DEB_HOST_MULTIARCH)/thruk/phantomjs" >> debian/thruk-plugin-reporting.lintian-overrides
echo "thruk-plugin-reporting: embedded-library libpng usr/lib/$(DEB_HOST_MULTIARCH)/thruk/phantomjs" >> debian/thruk-plugin-reporting.lintian-overrides
echo "thruk-plugin-reporting: embedded-library openssl usr/lib/$(DEB_HOST_MULTIARCH)/thruk/phantomjs" >> debian/thruk-plugin-reporting.lintian-overrides
echo "thruk-plugin-reporting: embedded-library sqlite usr/lib/$(DEB_HOST_MULTIARCH)/thruk/phantomjs" >> debian/thruk-plugin-reporting.lintian-overrides
echo "thruk-plugin-reporting: embedded-library zlib usr/lib/$(DEB_HOST_MULTIARCH)/thruk/phantomjs" >> debian/thruk-plugin-reporting.lintian-overrides
echo "thruk-plugin-reporting: hardening-no-relro usr/lib/$(DEB_HOST_MULTIARCH)/thruk/phantomjs" >> debian/thruk-plugin-reporting.lintian-overrides
sed -e 's|phantomjs,||' -i debian/control

override_dh_gencontrol:
dh_gencontrol -- -Vextra:Depends=perlapi-$(PERLVER)

override_dh_strip:
dh_strip --exclude=phantomjs
dh_strip

override_dh_auto_test:

Expand Down
1 change: 0 additions & 1 deletion debian/thruk-base.install
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
/usr/share/thruk/script/thruk_fastcgi.pl
/usr/share/thruk/script/thruk.psgi
/usr/share/thruk/script/grafana_export.sh
/usr/share/thruk/script/html2pdf.js
/usr/share/thruk/script/puppeteer.js
/usr/share/thruk/script/html2pdf.sh
/usr/share/thruk/script/pnp_export.sh
Expand Down
9 changes: 4 additions & 5 deletions docs/documentation/configuration.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -2959,15 +2959,14 @@ drop down selection.
== Component Thruk::Plugin::Reports2

The 'Reports2' plugin creates sla reports in html or pdf format. You
probably have to download the link:/documentation/faq.html#phantomjs[phantomjs binary] in a recent version.
probably have to install link:/documentation/faq.html#puppeteer[puppeteer] in a recent version.

ex.:

<Component Thruk::Plugin::Reports2>
report_nice_level = 5
max_concurrent_reports = 2
report_base_url = http://host.local/thruk/cgi-bin/
phantomjs = /usr/bin/phantomjs
pnp_export = script/pnp_export.sh
grafana_export = script/grafana_export.sh
report_from_email = User Name <[email protected]>
Expand All @@ -2987,9 +2986,9 @@ they will be queued up. Default is 2.
Url used to replace relative links in html reports.

=== phantomjs
`phantomjs` is used to convert html pages into pdf.
See the link:/documentation/faq.html#phantomjs[FAQ] for download
links and further information.
`phantomjs` is deprecated and no longer use. It has been replaced
with puppeteer. See the link:/documentation/faq.html#puppeteer[FAQ]
for further information.

=== pnp_export
pnp_export defines a script which exports a PNP4nagios graph into a
Expand Down
13 changes: 9 additions & 4 deletions docs/documentation/faq.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ of the file.
You may also wish to modify your `/etc/thruk/thruk_local.conf` to use an updated `cookie_auth_restricted_url`:
---
cookie_auth_restricted_url = https://localhost/thruk/cgi-bin/restricted.cgi
---
Finally reload Apache:
Expand Down Expand Up @@ -234,12 +234,17 @@ folder.
=== wkhtmltopdf
wkhtmltopdf is no longer required and has been replaced by phantomjs.
wkhtmltopdf is no longer required and has been replaced by puppeteer.
=== phantomjs
phantomjs is required to create PDF reports with the reports2 plugin. You can get
phantomjs from http://phantomjs.org/ if it's not available for your system.
phantomjs is no longer required and has been replaced by puppeteer.
=== puppeteer
puppeteer is required to create PDF reports with the reports2 plugin. You can read
more about puppeteer on https://pptr.dev/ OMD starting with version 5 has puppeteer
already included.
=== How can I enable the business process addon.
Expand Down
2 changes: 1 addition & 1 deletion docs/documentation/reporting.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ perfectly documented at http://template-toolkit.org/docs/manual/index.html

==== Converting

The generated HTML report will be converted into a pdf file using phantomjs.
The generated HTML report will be converted into a pdf file using puppeteer.


==== Sending Reports By Mail
Expand Down
17 changes: 17 additions & 0 deletions lib/Thruk/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,23 @@ sub wildcard_match {
return;
}

########################################

=head2 has_binary
has_binary($bin)
returns true if binary is found in path
=cut
sub has_binary {
my($bin) = @_;
for my $p (split/:/mx, $ENV{'PATH'}) {
return 1 if -x $p."/".$bin;
}
return;
}

##############################################

=head1 SEE ALSO
Expand Down
27 changes: 26 additions & 1 deletion lib/Thruk/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,6 @@ sub get_perf_image {

# create fake session
my($sessionid) = get_fake_session($c);
local $ENV{PHANTOMJSSCRIPTOPTIONS} = '--cookie=thruk_auth,'.$sessionid.' --format='.$options->{'format'};
local $ENV{THRUK_SESSION_ID} = $sessionid;

# call login hook, because it might transfer our sessions to remote graphers
Expand Down Expand Up @@ -3837,4 +3836,30 @@ sub render_db_profile {

##############################################

=head2 has_node_module
has_node_module($c, $module_name)
return true if npm module is installed
=cut
sub has_node_module {
my($c, $module_name) = @_;
return unless Thruk::Base::has_binary("node");
return unless Thruk::Base::has_binary("npm");

my($out, $rc) = Thruk::Utils::IO::cmd($c, ["npm", "ls", "-g"]);
if($out =~ m/$module_name/mx) {
return 1;
}

($out, $rc) = Thruk::Utils::IO::cmd($c, ["npm", "ls"]);
if($out =~ m/$module_name/mx) {
return 1;
}
return;
}

##############################################

1;
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ sub index {
$c->stash->{infoBoxTitle} = 'Reporting';
$c->stash->{has_jquery_ui} = 1;
$c->stash->{has_debug_options} = 1;
$c->stash->{'phantomjs'} = 1;
$c->stash->{'puppeteer'} = 1;
$c->stash->{'disable_backspace'} = 1;
$c->stash->{'filtered'} = 0;
$c->stash->{'plugin_name'} = Thruk::Utils::get_plugin_name(__FILE__, __PACKAGE__);
Expand Down Expand Up @@ -159,9 +159,8 @@ sub index {
}
}

if($c->config->{'Thruk::Plugin::Reports2'}->{'phantomjs'} && !-x $c->config->{'Thruk::Plugin::Reports2'}->{'phantomjs'}) {
$c->stash->{'phantomjs'} = 0;
$c->stash->{'phantomjs_file'} = $c->config->{'Thruk::Plugin::Reports2'}->{'phantomjs'};
if(!$ENV{'OMD_ROOT'} && !Thruk::Utils::has_node_module($c, 'puppeteer-core')) {
$c->stash->{'puppeteer'} = 0;
}

# show list of configured reports
Expand Down
15 changes: 2 additions & 13 deletions plugins/plugins-available/reports2/lib/Thruk/Utils/Reports.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,7 @@ sub _verify_fields {

##########################################################
sub _convert_to_pdf {
my($c, $reportdata, $attachment, $nr, $logfile, $nodelay) = @_;
my($c, $reportdata, $attachment, $nr, $logfile, $is_report) = @_;
$c->stats->profile(begin => "_convert_to_pdf()");

my $htmlfile = $c->config->{'var_path'}.'/reports/'.$nr.'.html';
Expand Down Expand Up @@ -1760,18 +1760,7 @@ sub _convert_to_pdf {
return;
}

my $phantomjs = $c->config->{'Thruk::Plugin::Reports2'}->{'phantomjs'} || 'phantomjs';
my $autoscale = 0;
if($c->stash->{'param'}->{'pdf'}) {
$autoscale = 1;
}

my $phantomjsscriptoptions = '';
$phantomjsscriptoptions .= ' --autoscale=1' if $autoscale;
$phantomjsscriptoptions .= ' --nodelay=1' if $nodelay;
local $ENV{PHANTOMJSSCRIPTOPTIONS} = $phantomjsscriptoptions if $phantomjsscriptoptions;
my $cmd = $c->config->{home}.'/script/html2pdf.sh "'.$htmlfile.'" "'.$attachment.'.pdf" "'.$logfile.'" "'.$phantomjs.'"';
_debug("converting env: PHANTOMJSSCRIPTOPTIONS: %s", $ENV{PHANTOMJSSCRIPTOPTIONS}//'');
my $cmd = $c->config->{home}.'/script/html2pdf.sh "file://'.$htmlfile.'" "'.$attachment.'.pdf" "'.$logfile.'" "'.($is_report//0).'"';
_debug("converting to pdf: ".$cmd);
my $out = Thruk::Utils::IO::cmd($cmd.' 2>&1');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,8 @@ sub get_url {
# directly convert external urls
if($url =~ m/^https?:\/\/([^\/]+)/mx && $c->stash->{'param'}->{'pdf'} && $c->stash->{'param'}->{'pdf'} eq 'yes') {
Thruk::Utils::External::update_status($ENV{'THRUK_JOB_DIR'}, 80, 'converting') if $ENV{'THRUK_JOB_DIR'};
my $phantomjs = $c->config->{'Thruk::Plugin::Reports2'}->{'phantomjs'} || 'phantomjs';
my $cmd = $c->config->{home}.'/script/html2pdf.sh "'.$url.'" "'.$c->stash->{'attachment'}.'.pdf" "" "'.$phantomjs.'"';
local $ENV{PHANTOMJSSCRIPTOPTIONS} = '--cookie=thruk_auth,'.$sessionid;
my $cmd = $c->config->{home}.'/script/html2pdf.sh "'.$url.'" "'.$c->stash->{'attachment'}.'.pdf"';
local $ENV{THRUK_SESSION_ID} = $sessionid;
Thruk::Utils::IO::cmd($cmd);
move($c->stash->{'attachment'}.'.pdf', $c->stash->{'attachment'}) or die('move '.$c->stash->{'attachment'}.'.pdf to '.$c->stash->{'attachment'}.' failed: '.$!);
$Thruk::Utils::PDF::ctype = 'application/pdf';
Expand Down
2 changes: 1 addition & 1 deletion plugins/plugins-available/reports2/root/reports_render.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function render_total_sla_graph(nr, title, data, sla, graph_min_sla, type, label

var height = data.length * 20;
if(height < 300) { height = 300; }
if(height > 650) { height = 650; }
if(height > 800) { height = 800; }
jQuery("#flotgraph"+nr).css('height', height+"px");

var ticks = [];
Expand Down
6 changes: 3 additions & 3 deletions plugins/plugins-available/reports2/templates/reports.tt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

[% PROCESS _infobox.tt %]

[% IF !phantomjs %]
[% IF !puppeteer %]
<div class="card red alert top-center w-[550px]">
<div class="head">
<h3>Missing Converter!</h3>
</div>
<div class="body">
[% phantomjs_file %] missing, no pdfs can be generated.<br>
<i class="uil uil-external-link-alt"></i> <a class="link" href="http://www.thruk.org/faq.html#_phantomjs" target="_blank">please read the FAQ.</a>
Puppeteer is missing, no pdfs can be generated.<br>
<i class="uil uil-external-link-alt"></i> <a class="link" href="http://www.thruk.org/faq.html#_puppeteer" target="_blank">please read the FAQ.</a>
</div>
</div>
[% END %]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jQuery(document).ready(function() {
}
[% END %]

var max_entries_per_page = 32;
var max_entries_per_page = 40;
render_total_sla_graph([% nr %], "[% loc("Availability") %]", graph_data, [% param.sla %], [% param.graph_min_sla %], "[% type | html %]", label, max_entries_per_page);
});
-->
Expand Down
Loading

0 comments on commit 2c8ff31

Please sign in to comment.