2

I am facing the error "Undefined subroutine &main::header called at /opt/alu-rp/www/cgi/munin-cgi-html line 54." while opening the munin page(http://localhost/munin)

Perl version: v5.32.0 Munin version: v2.0.65

With the error, able to see the header is not initiated due to the new condition added in munin-cgi-html

# grab config
html_startup(\@params);
while(new CGI::Fast){
    print header("text/html");
    $config = get_config(1);
    show_page();
}
:
:
# CGI in perl 5.20 is now seriously broken as it doesn't import into the namespace.
# So we have to delegate explicitly. It's easier than prefixing with CGI:: each use.
# This workaround is applied only if "header" is undefined (i.e. for perl >= 5.20).
if(!defined &header){
        *header = sub { return CGI::header(@_); };
        *path_info = sub { return CGI::path_info(@_); };
        *url = sub { return CGI::url(@_); };
        *script_name = sub { return CGI::script_name(@_); };
}

Adding a line in munin-cgi-html able to solve the issue.

sub header { return CGI::header(@_); }

But not sure what will be the impact of adding this line. Is there anything specific configuration or package needs to install for Munin to work?

ragul rangarajan
  • 167
  • 2
  • 12

1 Answers1

4

The block on the bottom is importing symbols from CGI. Unfortunately, you are trying to use header before executing this block to import it. You need to execute the imports before all uses of header and such.


Note that

*header = sub { return CGI::header(@_); };

is better written as

*header = \&CGI::header

as it avoids a needless extra sub call.


Note that you can ask CGI.pm to export those symbols for you. Instead of manually importing the symbols, you can simply use either of following:

use CGI qw( header path_info url script_name );
use CGI qw( :cgi );

No need to clunckily import the symbols yourself.

ikegami
  • 367,544
  • 15
  • 269
  • 518
  • 2
    You should probably mention that once the import is done correctly, that entire `if (!defined &header) {...}` block can be discarded. – tobyink Jan 11 '21 at 19:45
  • @tobyink I wasn't fully awake when I answered. I have rewritten my Answer to provide a better answer to the question. – ikegami Jan 11 '21 at 19:55
  • Thanks, that really worked. But what I am looking for Is whether am I missing any configuration/perl module in Munin installation with respect to perl. Since the particular munin-cgi-html file is part of Munin. – ragul rangarajan Jan 12 '21 at 09:12