File: gen_plugin_deps.pl

package info (click to toggle)
monitoring-plugins 2.2-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 9,740 kB
  • ctags: 6,699
  • sloc: ansic: 60,011; sh: 13,872; perl: 6,291; makefile: 475
file content (106 lines) | stat: -rw-r--r-- 2,288 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#! /usr/bin/perl
#
# collectd - gen_plugin_deps.pl
# Copyright (C) 2007 Sebastian Harl
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; only version 2 of the License is applicable.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
#
# Author:
#   Sebastian Harl <sh at tokkee.org>

use strict;
use warnings;

# actual not needed
my $extra_deps = {
#	sensors => [ 'lm-sensors' ],
};

my $infile  = "debian/README.Debian.plugins.in";
my $outfile = "debian/README.Debian.plugins";

my ($ifile, $ofile);

if (! open($ifile, "<", $infile)) {
	print STDERR "Could not open file '$infile': $!\n";
	exit 1;
}

if (! open($ofile, ">", $outfile)) {
	print STDERR "Could not open file '$outfile': $!\n";
	exit 1;
}

while (my $line = <$ifile>) {
	if ($line !~ m/^\@PLUGIN_DEPS\@\n$/) {
		print $ofile $line;
	}
	else {
		print_plugin_deps($ofile);
	}
}

close($ofile);
close($ifile);

sub print_plugin_deps
{
	my $fh   = shift;
	my $pdir = undef;
	my $i    = 0;

	my $plugindir = "debian/monitoring-plugins-standard/usr/lib/nagios/plugins/";

	if (! opendir($pdir, $plugindir)) {
		print STDERR "Could not open directory '$plugindir': $!\n";
		exit 1;
	}

	foreach my $dirent (sort readdir($pdir)) {
#		if ($dirent !~ m/^(\w+).so$/) {
		if ($dirent !~ m/^check_(\w+)$/) {
			next;
		}

		my $name = $1;
		my $deps = `dpkg-shlibdeps -O $plugindir/$dirent`;

		chomp $deps;

		$deps =~ s/^shlibs:Depends=//;

		my @deps = grep !m/^libc6\b/, split m/, /, $deps;

		if (scalar @deps) {
			if (0 < $i) {
				print $fh "\n";
			}

			++$i;

			print $fh "check_$name:\n";

			if (defined $extra_deps->{$name}) {
				unshift @deps, @{$extra_deps->{$name}};
			}

			foreach my $dep (@deps) {
				print $fh "  * $dep\n";
			}
		}
	}
}

# vim: set tw=78 sw=4 ts=4 noexpandtab :