2009-08-03 Ramon Novoa <rnovoa@artica.es>

* linux/plugins/inventory: Added the capacity for search services in init,
	details file system, and modify the software scanner to extract the
	description.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1836 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2009-08-11 15:19:30 +00:00
parent b2aa119ce2
commit 28096d7520
3 changed files with 142 additions and 5 deletions

View File

@ -6,7 +6,7 @@
#
# inventory Generate a hardware/software inventory.
#
# Sample usage: ./inventory <interval in days> [cpu] [ram] [video] [nic] [hd] [cdrom] [software]
# Sample usage: ./inventory <interval in days> [cpu] [ram] [video] [nic] [hd] [cdrom] [software] [init_services] [filesystem]
#
# 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
@ -48,6 +48,48 @@ sub get_module_data ($$$$) {
push (@{$modules->{$name}}, \%module);
}
# Get a list of information file system in machine
sub get_file_system($$) {
my ($name, $modules) = @_;
my @fileSystems = `df -h | tail -n +2`; #remove the titles of columns
foreach my $row (@fileSystems) {
next unless ($row =~ /^(\S+)\s+\S+\s+(\S+)\s+(\S+)\s+\S+\s+(\S+)/);
my %module;
$module{'filesystem'} = $1;
$module{'used'} = $2;
$module{'avail'} = $3;
$module{'mount'} = $4;
$module{'_keys'} = ['filesystem', 'used','avail', 'mount'];
push (@{$modules->{$name}}, \%module);
}
}
# Get a list of services init in machine
sub get_servicies_init_machine($$) {
my ($name, $modules) = @_;
my $runlevel = `runlevel | cut -d' ' -f2`;
#ini trim($runlevel)
$runlevel =~ s/^\s*//; #ltrim
$runlevel =~ s/\s*$//; #rtrim
#end trim($runlevel)
my $script = "ls /etc/rc" . $runlevel .".d/ -l | grep \"^l.*\" | grep \" S.* \" | cut -d' ' -f11";
my @services = `$script`;
foreach my $row (@services) {
next unless ($row =~ /^\S+\/(\S+)$/);
my %module;
$module{'service'} = $1;
$module{'_keys'} = ['service'];
push (@{$modules->{$name}}, \%module);
}
}
# Get a list of installed programs
sub get_software_module_data ($$) {
my ($name, $modules) = @_;
@ -68,12 +110,14 @@ sub get_software_module_data ($$) {
# Parse data
foreach my $row (@soft) {
next unless ($row =~ /^ii\s+(\S+)\s+(\S+)/);
next unless ($row =~ /^ii\s+(\S+)\s+(\S+)\s+([^\n]+)/);
my %module;
$module{'program'} = $1;
$module{'version'} = $2;
$module{'_keys'} = ['program', 'version'];
$module{'description'} = $3;
$module{'_keys'} = ['program', 'version','description'];
push (@{$modules->{$name}}, \%module);
}
}
@ -101,7 +145,7 @@ sub print_module ($$) {
# Check command line parameters
if ($#ARGV < 0) {
print "Usage: $0 <interval> [cpu] [ram] [video] [nic] [hd] [cdrom] [software]\n\n";
print "Usage: $0 <interval> [cpu] [ram] [video] [nic] [hd] [cdrom] [software] [init_services] [filesystem]\n\n";
exit 1;
}
@ -168,6 +212,17 @@ if ($enable_all == 1 || $enabled{'software'} == 1) {
get_software_module_data ('Software', \%modules);
}
#init_services
if ($enable_all == 1 || $enabled{'init_services'} == 1) {
get_servicies_init_machine ('Init services', \%modules);
}
#filesystem
if ($enable_all == 1 || $enabled{'filesystem'} == 1) {
get_file_system('File system', \%modules);
}
# Print module data
print "<inventory>\n";
while (my ($name, $module) = each (%modules)) {

View File

@ -0,0 +1,10 @@
Agent_1
Agent_2
Agent_3
Agent_4
Agent_5
Agent_6
Agent_7
Agent_8
Agent_9
Agent_10

View File

@ -0,0 +1,72 @@
# Maximum number of threads, by default 10.
max_threads 10
# File containing a list of agent names (one per line).
agent_file agent_names.txt
# Directory where XML data files will be placed, by default /tmp.
temporal /var/spool/pandora/data_in
# Pandora FMS XML Stress log file, logs to stdout by default.
#log_file pandora_xml_stress.log
# XML version, by default 1.0.
xml_version 1.0
# XML encoding, by default ISO-8859-1.
encoding ISO-8859-1
# Operating system (shared by all agents), by default Linux.
os_name Linux
# Operating system version (shared by all agents), by default 2.6.
os_version 2.6
# Agent interval, by default 300.
agent_interval 300
# Data file generation start date, by default now.
time_from 2009-07-20 00:00:00
# Data file generation end date, by default now.
#time_to 2009-06-05 00:00:00
# Delay after generating the first data file for each agent to avoid
# race conditions when auto-creating the agent, by default 2.
startup_delay 2
# Address of the Tentacle server where XML files will be sent (optional).
# server_ip 192.168.50.1
# Port of the Tentacle server, by default 41121.
# server_port 41121
# Module definitions. Similar to pandora_agent.conf.
module_begin
module_name Module_1
module_type generic_data
module_descripcion Module 1 description.
module_max 100
module_min 0
# Probability of the module data changing, by default 100%
module_variation 100
module_end
module_begin
module_name Module_2
module_type generic_data_string
module_descripcion Module 2 description.
# Maximum string length, by default 0.
module_max 20
# Minimum string length, by default 0
module_min 10
module_end
module_begin
module_name Module_3
module_type generic_proc
module_descripcion Module 3 description.
# Initial data.
module_data 1
module_end