| | 750 | } |
|---|
| | 751 | |
|---|
| | 752 | if (defined $key->{'ngraphs'} and $key->{'ngraphs'}) { |
|---|
| | 753 | my $graphtemplate = HTML::Template->new( |
|---|
| | 754 | filename => munin_get ($config, "tmpldir", "")."/munin-nodeview.tmpl", |
|---|
| | 755 | die_on_bad_params => 0, |
|---|
| | 756 | loop_context_vars => 1, |
|---|
| | 757 | filter => sub { my $ref=shift; $$ref =~ s/URLX/URL$key->{'depth'}/g; } |
|---|
| | 758 | ); |
|---|
| | 759 | |
|---|
| | 760 | $graphtemplate->param ( |
|---|
| | 761 | GROUPS => $key->{'groups'}, |
|---|
| | 762 | PATH => $key->{'path'}, |
|---|
| | 763 | CSSPATH => $key->{'csspath'}, |
|---|
| | 764 | PEERS => $key->{'peers'}, |
|---|
| | 765 | PARENT => $key->{'path'}->[-2]->{'name'}, |
|---|
| | 766 | NAME => $key->{'name'}, |
|---|
| | 767 | CATEGORIES => $key->{'categories'}, |
|---|
| | 768 | NCATEGORIES => $key->{'ncategories'}, |
|---|
| | 769 | ); |
|---|
| | 770 | my $filename = $key->{'filename'}; |
|---|
| | 771 | open (FILE, ">$filename") or |
|---|
| | 772 | die "Cannot open $filename for writing: $!"; |
|---|
| | 773 | print FILE $graphtemplate->output; |
|---|
| | 774 | close FILE; |
|---|
| | 775 | } |
|---|
| | 776 | } |
|---|
| | 777 | } |
|---|
| | 778 | } |
|---|
| | 779 | |
|---|
| | 780 | sub generate_service_templates { |
|---|
| | 781 | } |
|---|
| | 782 | |
|---|
| | 783 | sub generate_service_templates { |
|---|
| | 784 | |
|---|
| | 785 | my $service = shift || return undef; |
|---|
| | 786 | return undef unless munin_get_bool ($service, "graph", 1); |
|---|
| | 787 | |
|---|
| | 788 | my %srv; |
|---|
| | 789 | my $fieldnum = 0; |
|---|
| | 790 | my @graph_info; |
|---|
| | 791 | my @field_info; |
|---|
| | 792 | my @loc = munin_get_node_loc ($service); |
|---|
| | 793 | my $pathnodes = get_path_nodes ($service); |
|---|
| | 794 | my $peers = get_peer_nodes ($service, lc munin_get ($service, "graph_category", "other")); |
|---|
| | 795 | (my $csspath = $pathnodes->[0]->{'link'}) =~ s/index.html$/style.css/; |
|---|
| | 796 | |
|---|
| | 797 | $srv{'node'} = munin_get_node_name ($service); |
|---|
| | 798 | logger("processing service: $srv{node}"); |
|---|
| | 799 | $srv{'service'} = $service; |
|---|
| | 800 | $srv{'label'} = munin_get ($service, "graph_title"); |
|---|
| | 801 | $srv{'category'} = lc( munin_get ($service, "graph_category", "other") ); |
|---|
| | 802 | |
|---|
| | 803 | my $method = munin_get ($service, "graph_strategy", "cron"); |
|---|
| | 804 | |
|---|
| | 805 | $srv{'url'} = "$srv{node}.html"; |
|---|
| | 806 | |
|---|
| | 807 | my $path = join ('/', @loc); |
|---|
| | 808 | |
|---|
| | 809 | if ($method eq "cgi") { |
|---|
| | 810 | $srv{'imgday'} =$config->{'cgiurl_graph'}."/$path-day.png"; |
|---|
| | 811 | $srv{'imgweek'} =$config->{'cgiurl_graph'}."/$path-week.png"; |
|---|
| | 812 | $srv{'imgmonth'}=$config->{'cgiurl_graph'}."/$path-month.png"; |
|---|
| | 813 | $srv{'imgyear'} =$config->{'cgiurl_graph'}."/$path-year.png"; |
|---|
| | 814 | |
|---|
| | 815 | if (munin_get_bool ($service, "graph_sums", 0)) { |
|---|
| | 816 | $srv{'imgweeksum'} = $config->{'cgiurl_graph'}."/$path-week-sum.png"; |
|---|
| | 817 | $srv{'imgyearsum'} = $config->{'cgiurl_graph'}."/$path-year-sum.png"; |
|---|
| | 818 | } |
|---|
| | 819 | } else { |
|---|
| | 820 | # graph strategy cron |
|---|
| | 821 | |
|---|
| | 822 | $srv{'imgday'} ="$srv{node}-day.png"; |
|---|
| | 823 | $srv{'imgweek'} ="$srv{node}-week.png"; |
|---|
| | 824 | $srv{'imgmonth'}="$srv{node}-month.png"; |
|---|
| | 825 | $srv{'imgyear'} ="$srv{node}-year.png"; |
|---|
| | 826 | |
|---|
| | 827 | for my $scale (@times) { |
|---|
| | 828 | if (my ($w, $h) = get_png_size(munin_get_picture_filename($service, $scale))) { |
|---|
| | 829 | $srv{"img".$scale."width"} = $w; |
|---|
| | 830 | $srv{"img".$scale."height"} = $h; |
|---|
| 752 | | } |
|---|
| | 833 | |
|---|
| | 834 | if (munin_get_bool ($service, "graph_sums", 0)) { |
|---|
| | 835 | $srv{imgweeksum} = "$srv{node}-week-sum.png"; |
|---|
| | 836 | $srv{imgyearsum} = "$srv{node}-year-sum.png"; |
|---|
| | 837 | for my $scale (["week", "year"]) { |
|---|
| | 838 | if (my ($w, $h) = get_png_size (munin_get_picture_filename($service, $scale, 1))) { |
|---|
| | 839 | $srv{"img".$scale."sumwidth"} = $w; |
|---|
| | 840 | $srv{"img".$scale."sumheight"} = $h; |
|---|
| | 841 | } |
|---|
| | 842 | } |
|---|
| | 843 | } |
|---|
| | 844 | } |
|---|
| | 845 | |
|---|
| | 846 | # Do "help" section |
|---|
| | 847 | if (my $info = munin_get ($service, "graph_info")) { |
|---|
| | 848 | my %graph_info; |
|---|
| | 849 | $graph_info{info} = $info; |
|---|
| | 850 | push @{$srv{graphinfo}}, \%graph_info; |
|---|
| | 851 | } |
|---|
| | 852 | |
|---|
| | 853 | $srv{fieldlist} .= "<tr><th align='left' valign='top'>Field</th><th align='left' valign='top'>Type</th><th align='left' valign='top'>Warn</th><th align='left' valign='top'>Crit</th><th></tr>"; |
|---|
| | 854 | foreach my $f (@{munin_get_field_order ($service)}) { |
|---|
| | 855 | $f =~ s/=(.*)$//; |
|---|
| | 856 | my $path = $1; |
|---|
| | 857 | next if (!defined $service->{$f}); |
|---|
| | 858 | my $fieldobj = $service->{$f}; |
|---|
| | 859 | next if (ref ($fieldobj) != "HASH" or !defined $fieldobj->{'label'}); |
|---|
| | 860 | next if (!munin_draw_field ($fieldobj)); |
|---|
| | 861 | |
|---|
| | 862 | logger ("DEBUG: single_value: Checking field \"$f\" ($path).") |
|---|
| | 863 | if $DEBUG; |
|---|
| | 864 | |
|---|
| | 865 | if (defined $path) { |
|---|
| | 866 | # This call is to make sure field settings are copied |
|---|
| | 867 | # for aliases, .stack, et al. Todo: put that part of |
|---|
| | 868 | # munin_get_rrd_filename into its own functino. |
|---|
| | 869 | munin_get_rrd_filename ($f, $path); |
|---|
| | 870 | } |
|---|
| | 871 | |
|---|
| | 872 | my %field_info; |
|---|
| | 873 | $fieldnum++; |
|---|
| | 874 | |
|---|
| | 875 | $field_info{'hr'} = 1 unless ($fieldnum % 3); |
|---|
| | 876 | $field_info{'field'} = $f; |
|---|
| | 877 | $field_info{'label'} = munin_get ($fieldobj, "label", $f); |
|---|
| | 878 | $field_info{'type'} = lc( munin_get ($fieldobj, "type", "GAUGE") ); |
|---|
| | 879 | $field_info{'warn'} = munin_get ($fieldobj, "warning"); |
|---|
| | 880 | $field_info{'crit'} = munin_get ($fieldobj, "critical"); |
|---|
| | 881 | $field_info{'info'} = munin_get ($fieldobj, "info"); |
|---|
| | 882 | |
|---|
| | 883 | my $state = munin_field_status ($config, $limits, 1); |
|---|
| | 884 | |
|---|
| | 885 | if (defined $state) { |
|---|
| | 886 | $field_info{'state_warning'} = 1 if $state eq "warning"; |
|---|
| | 887 | $field_info{'state_critical'} = 1 if $state eq "critical"; |
|---|
| | 888 | $field_info{'state_unknown'} = 1 if $state eq "unknown"; |
|---|
| | 889 | } |
|---|
| | 890 | push @{$srv{'fieldinfo'}}, \%field_info; |
|---|
| | 891 | } |
|---|
| | 892 | |
|---|
| | 893 | my $state = munin_service_status ($service, $limits, 1); |
|---|
| | 894 | if (defined $state) { |
|---|
| | 895 | $srv{'state_warning'} = 1 if $state eq "warning"; |
|---|
| | 896 | $srv{'state_critical'} = 1 if $state eq "critical"; |
|---|
| | 897 | $srv{'state_unknown'} = 1 if $state eq "unknown"; |
|---|
| | 898 | } |
|---|
| | 899 | |
|---|
| | 900 | $servicetemplate->param(SERVICES => [\%srv], |
|---|
| | 901 | PATH => $pathnodes, |
|---|
| | 902 | PEERS => $peers, |
|---|
| | 903 | CSS => $csspath, |
|---|
| | 904 | CATEGORY => ucfirst $srv{'category'}, |
|---|
| | 905 | TIMESTAMP => $timestamp); |
|---|
| | 906 | my $filename = munin_get_html_filename ($service); |
|---|
| | 907 | open (FILE, ">$filename") or |
|---|
| | 908 | die "Cannot open $filename for writing: $!"; |
|---|
| | 909 | print FILE $servicetemplate->output; |
|---|
| | 910 | close FILE; |
|---|
| | 911 | |
|---|
| | 912 | return \%srv; |
|---|