2010-11-04 Sancho Lerena <slerena@artica.es>

* NT4: New binary version of Unix perl agent for NT4, with some tools.
        .exe compiled with ActiveState SDK 9.0

        * pandora_agent: Some small modifications to make it work nicely in 
        windows boxes.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3531 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
slerena 2010-11-04 19:34:04 +00:00
parent 97ef472bee
commit 239c6e3aac
29 changed files with 404 additions and 19 deletions

View File

@ -1,3 +1,11 @@
2010-11-04 Sancho Lerena <slerena@artica.es>
* NT4: New binary version of Unix perl agent for NT4, with some tools.
.exe compiled with ActiveState SDK 9.0
* pandora_agent: Some small modifications to make it work nicely in
windows boxes.
2010-11-02 Raul Mateos <raulofpandora@gmail.com>
* tentacle_client: Fixed year from last commit. Converted some spaces

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,33 @@
' df.vbs
' Returns free space for avaible drives.
' --------------------------------------
Option Explicit
On Error Resume Next
' Variables
Dim objWMIService, objItem, colItems, argc, argv, i
' Parse command line parameters
argc = Wscript.Arguments.Count
Set argv = CreateObject("Scripting.Dictionary")
For i = 0 To argc - 1
argv.Add Wscript.Arguments(i), i
Next
' Get drive information
Set objWMIService = GetObject ("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32_LogicalDisk")
For Each objItem in colItems
If argc = 0 Or argv.Exists(objItem.Name) Then
If objItem.FreeSpace <> "" Then
Wscript.StdOut.WriteLine "<module>"
Wscript.StdOut.WriteLine " <name><![CDATA[" & objItem.Name & "]]></name>"
Wscript.StdOut.WriteLine " <description><![CDATA[Drive " & objItem.Name & " free space in MB]]></description>"
Wscript.StdOut.WriteLine " <data><![CDATA[" & Int(objItem.FreeSpace /1048576) & "]]></data>"
Wscript.StdOut.WriteLine "</module>"
Wscript.StdOut.flush
End If
End If
Next

View File

@ -0,0 +1,38 @@
' df_all.vbs
' Returns free space (%) for all drives
' Pandora FMS Plugin, (c) 2010 Sancho Lerena
' ------------------------------------------
Option Explicit
On Error Resume Next
' Variables
Dim objWMIService, objItem, colItems, argc, argv, i, Percent
' Parse command line parameters
argc = Wscript.Arguments.Count
Set argv = CreateObject("Scripting.Dictionary")
For i = 0 To argc - 1
argv.Add Wscript.Arguments(i), i
Next
' Get drive information
Set objWMIService = GetObject ("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32_LogicalDisk")
For Each objItem in colItems
If argc = 0 Or argv.Exists(objItem.Name) Then
' Include only harddrivers (type 3)
If (objItem.FreeSpace <> "") AND (objItem.DriveType =3) Then
Percent = round ((objItem.FreeSpace / objItem.Size) * 100, 2)
Wscript.StdOut.WriteLine "<module>"
Wscript.StdOut.WriteLine " <name><![CDATA[DiskFree%_" & objItem.Name & "]]></name>"
Wscript.StdOut.WriteLine " <description><![CDATA[Drive " & objItem.Name & " % free space ]]></description>"
Wscript.StdOut.WriteLine " <data><![CDATA[" & Percent & "]]></data>"
Wscript.StdOut.WriteLine "</module>"
Wscript.StdOut.flush
End If
End If
Next

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,93 @@
' --------------------------------------------------------------
' WMI Log Event Parser for Windows
' Used as Plugin in Pandora FMS Monitoring System
' Written by Sancho Lerena <slerena@gmail.com> 2010
' Licensed under BSD Licence
' --------------------------------------------------------------
' This plugin uses three parameters:
'
' module_name : Module name to be reported at pandora, p.e: Event_Application
' logfile : Windows event logfile: Application, System, Security...
' interval: Should be the same interval agent has, p.e: 300 (seconds)
' Code begins here
' Take args from command line
if (Wscript.Arguments.Count = 0) then
WScript.Quit
end if
On Error Resume Next
cfg_module_name = Wscript.Arguments(0)
cfg_logfile = Wscript.Arguments(1)
cfg_interval = Wscript.Arguments(2)
strComputer = "."
MyDate = dateAdd("s", -cfg_interval, Now) ' Latest X seconds
Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime")
CONVERT_TO_LOCAL_TIME = TRUE
DateToCheck = CDate(MyDate)
dtmStartDate.SetVarDate DateToCheck, CONVERT_TO_LOCAL_TIME
WMI_QUERY = "Select * from Win32_NTLogEvent Where Logfile = '" & cfg_logfile & "' AND TimeWritten >= '" & dtmStartDate & "'"
' DEBUG
'wscript.StdOut.WriteLine dtmStartDate
'wscript.StdOut.WriteLine WMI_QUERY
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colEvents = objWMIService.ExecQuery (WMI_QUERY)
'The XML files need the have the fields SEVERITY, MESSAGE and
'STACKTRACE. These are the fields that are often used when logging with
'log4j. Just in case, the severity field can have the following values:
'TRACE, DEBUG, INFO, WARN, ERROR, FATAL. The "message" field is just
For Each objEvent in colEvents
if (objEvent.Type = "0") then
severity = "FATAL"
end if
if (objEvent.Type = "1") then
severity = "ERROR"
end if
if (objEvent.Type = "2") then
severity = "WARN"
end if
if (objEvent.Type >= "3") then
severity = "INFO"
end if
stacktrace = "Category: " & objEvent.CategoryString & ", Event Code: " & objEvent.EventCode & ", Source Name: " & objEvent.SourceName & ", LogFile: " & cfg_logfile
event_message = objEvent.Message
Wscript.StdOut.Write "<module>"
Wscript.StdOut.Write "<name><![CDATA[" & cfg_module_name & "]]></name>"
Wscript.StdOut.Write "<type>log4x</type>"
Wscript.StdOut.Write "<severity>" & severity & "</severity>"
if (event_message = "") then
Wscript.StdOut.Write "<message></message>"
else
Wscript.StdOut.Write "<message><![CDATA[" & event_message & "]]></message>"
end if
if (stacktrace = "") then
Wscript.StdOut.Write "<stacktrace></stacktrace>"
else
Wscript.StdOut.Write "<stacktrace><![CDATA[" & stacktrace & "]]></stacktrace>"
end if
Wscript.StdOut.WriteLine "</module>"
Wscript.StdOut.flush
Next
' Code ends here

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,25 @@
Pandora FMS for windows NT4
===========================
This agent is a port of the Unix agent (in perl) compiled with ActiveState DevKit Perl compiler. This is a stand-alone EXE with all the tools it will need to run. It has the same features than the Unix agent, but running on a NT4 box. This means can execute commands and get the output to produce data for Pandora FMS.
Could be used on any Windows machine (NT4, Win95, Windows 2000-2008, and of course Windows 7), could be useful on windows embedded systems without WMI core, which makes standard Pandora FMS windows agent to do not run properly.
Install
=======
Copy all contents on a directory of your choice, for example c:\pandora.
Edit pandora_agent.conf and set your parameters, including the log file and the temporal directory, should be something like c:\pandora\temp and c:\pandora\log. MAKE SURE that directories exists before trying to start Pandora agent.
Run
===
This agent does not run as a service, so you need to install in the startup menu or start by hand. The shortlink you create must have a parameter, which is where is the main Pandora FMS agent directory, in this scenario is c:\pandora, so the command to start will be :
c:\pandora\pandora_agent.exe c:\pandora
Install as a service
====================
srvany.exe tool is provided to do this. Is a microsoft resource kit tool to be able to use any .exe as a service. Just read the documentation about how to use srvany (provided in this package).

View File

@ -0,0 +1,140 @@
# Base config file for Pandora FMS agents
# Version 3.0, GNU/Linux
# Licensed under GPL license v2,
# Copyright (c) 2003-2009 Artica Soluciones Tecnologicas
# http://www.pandorafms.com
# General Parameters
# ==================
server_ip 192.168.50.1
server_path /var/spool/pandora/data_in
temporal c:\pandora\temp
logfile c:\pandora\log\pandora_agent.log
# Interval in seconds, 300 by default
interval 30
# Debug mode only generate XML, and stop after first execution,
# and does not copy XML to server.
debug 0
# Optional. UDP Server to receive orders from outside
# By default is disabled, set 1 to enable
# Set port (41122 by default)
# Set address to restrict who can order a agent restart (0.0.0.0 = anybody)
#
udp_server 1
udp_server_port 41122
udp_server_auth_address 0.0.0.0
# By default, agent takes machine name
# agent_name WinNT4_Test
#Parent agent_name
#parent_agent_name caprica
# Agent description
#description This is a demo agent for Linux
# Group assigned for this agent (descriptive, p.e: Servers)
#group Servers
# Autotime: Enforce to server to ignore timestamp coming from this
# agent, used when agents has no timer or it's inestable. 1 to enable
# this feature
#autotime 1
# Timezone offset: Difference with the server timezone
#timezone_offset 0
# Agent position paramters
# Those parameters define the geographical position of the agent
# latitude
#latitude 0
# longitude
#longitude 0
# altitude
#altitude 0
#Position description
#position_description Madrid, centro
# By default agent try to take default encoding defined in host.
#encoding iso-8859-15
# Listening TCP port for remote server. By default is 41121 (for tentacle)
# if you want to use SSH use 22, and FTP uses 21.
server_port 41121
# Transfer mode: tentacle, ftp, ssh or local
transfer_mode tentacle
# Server password (Tentacle or FTP). Leave empty for no password (default).
#server_pwd mypassword
# Set to yes/no to enable/disable OpenSSL support for Tentacle (disabled by default).
#server_ssl no
# Extra options for the Tentacle client (for example, server_opts "-v -r 5").
#server_opts
# delayed_startup defines number of MINUTES before start execution
# for first time when startup Pandora FMS Agent
#delayed_startup 10
# Pandora nice defines priority of execution. Less priority means more intensive execution
# A recommended value is 10. 0 priority means no Pandora CPU protection enabled (default)
#pandora_nice 0
# Cron mode replace Pandora FMS own task schedule each XX interval seconds by the use
# of old style cron. You should add to crontab Pandora FMS agent script to use this mode.
# This is disabled by default, and is not recommended. Use Pandora FMS internal scheduler
# is much more safe
#cron_mode
# If set to 1 allows the agent to be configured via the web console (Only Enterprise version)
remote_config 1
# Number of threads to execute modules in parallel
#agent_threads 1
# Secondary server configuration
# ==============================
# If secondary_mode is set to on_error, data files are copied to the secondary
# server only if the primary server fails. If set to always, data files are
# always copied to the secondary server.
#secondary_mode on_error
#secondary_server_ip localhost
#secondary_server_path /var/spool/pandora/data_in
#secondary_server_port 41121
#secondary_transfer_mode tentacle
#secondary_server_pwd mypassword
#secondary_server_ssl no
#secondary_server_opts
# Module Definition
# =================
# System information
# vmstat syntax depends on linux distro and vmstat command version, please check before use it
module_begin
module_name Disk_Free_C
module_type generic_data
module_exec dir c:\ | grep "bytes [a-z]*" | gawk "{ print $1 }" | tr -d ","
module_end
module_begin
module_name Service_EventLog
module_type generic_proc
module_exec net start | grep "EventLog" | wc -l | tr -d " "
module_end
module_begin
module_name Free_RAM
module_type generic_data
module_exec mem | grep "XMS" | gawk "{ print $1 }"
module_end

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,34 @@
' ps.vbs
' Returns the status of the given processes.
' -----------------------------------------
Option Explicit
'On Error Resume Next
' Variables
Dim objWMIService, objItem, colItems, argc, ps, i
' Get and hash process information
Set objWMIService = GetObject ("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32_Process")
Set ps = CreateObject("Scripting.Dictionary")
For Each objItem in colItems
if Not ps.Exists(objItem.Name) Then
ps.Add objItem.Name, 1
End If
Next
' Parse command line parameters and check each process
argc = Wscript.Arguments.Count
For i = 0 To argc - 1
Wscript.StdOut.WriteLine "<module>"
Wscript.StdOut.WriteLine " <name><![CDATA[" & Wscript.Arguments(i) & "]]></name>"
Wscript.StdOut.WriteLine " <description><![CDATA[Process " & Wscript.Arguments(i) & " status]]></description>"
If argc = 0 Or ps.Exists(Wscript.Arguments(i)) Then
Wscript.StdOut.WriteLine " <data><![CDATA[" & 1 & "]]></data>"
Else
Wscript.StdOut.WriteLine " <data><![CDATA[" & 0 & "]]></data>"
End If
Wscript.StdOut.WriteLine "</module>"
Wscript.StdOut.flush
Next

View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -56,8 +56,8 @@ if (!$@) {
$Sem = Thread::Semaphore->new;
}
use constant AGENT_VERSION => '3.2dev';
use constant AGENT_BUILD => '101015';
use constant AGENT_VERSION => '3.2RC1';
use constant AGENT_BUILD => '101103';
# Commands to retrieve total memory information in kB
use constant TOTALMEMORY_CMDS => {
@ -105,6 +105,7 @@ use constant PART_CMDS => {
# OS and OS version
my $OS = $^O;
my $OS_VERSION;
# Used to calculate the MD5 checksum of a string
@ -185,6 +186,12 @@ my %Parts = (
# Collections
my %Collections;
# $DevNull
my $DevNull = '/dev/null';
# Shell command separator
my $CmdSep = ';';
################################################################################
# Print usage information and exit.
################################################################################
@ -453,14 +460,14 @@ sub send_file {
my $output;
if ($Conf{'transfer_mode'} eq 'tentacle') {
$output = `tentacle_client -v -a $Conf{'server_ip'} -p $Conf{'server_port'} $Conf{'server_opts'} $file 2>&1 >/dev/null`;
$output = `tentacle_client -v -a $Conf{'server_ip'} -p $Conf{'server_port'} $Conf{'server_opts'} $file 2>&1 >$DevNull`;
} elsif ($Conf{'transfer_mode'} eq 'ssh') {
$output = `scp -P $Conf{'server_port'} $file pandora@"$Conf{'server_ip'}:$Conf{'server_path'}" 2>&1 >/dev/null`;
$output = `scp -P $Conf{'server_port'} $file pandora@"$Conf{'server_ip'}:$Conf{'server_path'}" 2>&1 >$DevNull`;
} elsif ($Conf{'transfer_mode'} eq 'ftp') {
my $base = basename ($file);
my $dir = dirname ($file);
$output = `ftp -n $Conf{'server_ip'} $Conf{'server_port'} 2>&1 >/dev/null <<FEOF1
$output = `ftp -n $Conf{'server_ip'} $Conf{'server_port'} 2>&1 >$DevNull <<FEOF1
quote USER pandora
quote PASS $Conf{'server_pwd'}
lcd "$dir"
@ -469,7 +476,7 @@ put "$base"
quit
FEOF1`
} elsif ($Conf{'transfer_mode'} eq 'local') {
$output = `cp $file $Conf{'server_path'}/ 2>&1 >/dev/null`;
$output = `cp $file $Conf{'server_path'}/ 2>&1 >$DevNull`;
}
# Get the errorlevel
@ -510,14 +517,14 @@ sub recv_file ($) {
my $output;
if ($Conf{'transfer_mode'} eq 'tentacle') {
$output = `cd "$Conf{'temporal'}"; tentacle_client -v -g -a $Conf{'server_ip'} -p $Conf{'server_port'} $Conf{'server_opts'} $file 2>&1 >/dev/null`
$output = `cd "$Conf{'temporal'}"$CmdSep tentacle_client -v -g -a $Conf{'server_ip'} -p $Conf{'server_port'} $Conf{'server_opts'} $file 2>&1 >$DevNull`
} elsif ($Conf{'transfer_mode'} eq 'ssh') {
$output = `scp -P $Conf{'server_port'} pandora@"$Conf{'server_ip'}:$Conf{'server_path'}/$file" $Conf{'temporal'} 2>&1 >/dev/null`;
$output = `scp -P $Conf{'server_port'} pandora@"$Conf{'server_ip'}:$Conf{'server_path'}/$file" $Conf{'temporal'} 2>&1 >$DevNull`;
} elsif ($Conf{'transfer_mode'} eq 'ftp') {
my $base = basename ($file);
my $dir = dirname ($file);
$output = `ftp -n $Conf{'server_ip'} $Conf{'server_port'} 2>&1 >/dev/null <<FEOF1
$output = `ftp -n $Conf{'server_ip'} $Conf{'server_port'} 2>&1 >$DevNull <<FEOF1
quote USER pandora
quote PASS $Conf{'server_pwd'}
lcd "$Conf{'temporal'}"
@ -526,7 +533,7 @@ get "$file"
quit
FEOF1`
} elsif ($Conf{'transfer_mode'} eq 'local') {
$output = `cp $Conf{'server_path'}/$file $Conf{'temporal'} 2>&1 >/dev/null`;
$output = `cp $Conf{'server_path'}/$file $Conf{'temporal'} 2>&1 >$DevNull`;
}
# Get the errorlevel
@ -646,7 +653,7 @@ sub check_collections () {
# Download and unzip
next unless (recv_file ($collection_file) == 0);
rmrf ("$ConfDir/collections/$collection");
`unzip -d "$ConfDir/collections/$collection" "$Conf{'temporal'}/$collection_file" 2>/dev/null`;
`unzip -d "$ConfDir/collections/$collection" "$Conf{'temporal'}/$collection_file" 2>$DevNull`;
unlink ("$Conf{'temporal'}/$collection_file");
# Save the new md5
@ -780,10 +787,17 @@ sub guess_os_version ($) {
# Linux
if ($os eq 'linux') {
$os_version = `lsb_release -sd 2>/dev/null`;
$os_version = `lsb_release -sd 2>$DevNull`;
# AIX
} elsif ($os eq 'aix') {
$os_version = "$2.$1" if (`uname -rv` =~ /\s*(\d)\s+(\d)\s*/);
# Windows
} elsif ($os =~ /win/i) {
$os_version = `ver`;
$DevNull = '/Nul';
$CmdSep = '\&';
$OS = "windows";
# Solaris, HP-UX, BSD and others
} else {
$os_version = `uname -r`;
@ -930,10 +944,10 @@ sub module_exec ($) {
# Execute the command
if ($module->{'timeout'} == 0) {
@data = `$module->{'params'} 2> /dev/null`;
@data = `$module->{'params'} 2> $DevNull`;
} else {
my $cmd = quotemeta ($module->{'params'});
@data = `$Conf{'pandora_exec'} $module->{'timeout'} $cmd 2> /dev/null`;
@data = `$Conf{'pandora_exec'} $module->{'timeout'} $cmd 2> $DevNull`;
}
# Something went wrong or no data
@ -1037,7 +1051,7 @@ sub module_cpuusage ($) {
# Get CPU usage
my $cmd = CPUUSAGE_CMDS->{$OS};
my @data = `$cmd 2> /dev/null`;
my @data = `$cmd 2> $DevNull`;
# Something went wrong or no data
return () unless ($? eq 0 && defined ($data[0]));
@ -1056,7 +1070,7 @@ sub module_freememory ($) {
# Get available memory
my $cmd = FREEMEMORY_CMDS->{$OS};
my @data = `$cmd 2> /dev/null`;
my @data = `$cmd 2> $DevNull`;
# Something went wrong or no data
return () unless ($? eq 0 && defined ($data[0]));
@ -1075,7 +1089,7 @@ sub module_freepercentmemory ($) {
# Get CPU usage
my $cmd = TOTALMEMORY_CMDS->{$OS};
my @data = `$cmd 2> /dev/null`;
my @data = `$cmd 2> $DevNull`;
# Something went wrong or no data
return () unless ($? eq 0 && defined ($data[0]));
@ -1104,7 +1118,7 @@ sub evaluate_module_conditions ($$) {
($condition->{'operator'} eq '!=' && $data != $condition->{'value_1'}) ||
($condition->{'operator'} eq '=~' && $data =~ /$condition->{'value_1'}/) ||
($condition->{'operator'} eq '()' && $data > $condition->{'value_1'} && $data < $condition->{'value_2'})) {
`$condition->{'command'} 2> /dev/null`;
`$condition->{'command'} 2> $DevNull`;
}
}
}
@ -1257,7 +1271,7 @@ sub udp_server ($$) {
sub exec_plugin ($) {
my $plugin = shift;
my $output = `$plugin 2>/dev/null`;
my $output = `$plugin 2>$DevNull`;
# Do not save the output if there was an error
return unless ($? eq 0);