PDA

View Full Version : Couple Of UserParameter checks


James Wells
18-08-2005, 01:05
Greetings,

With the new Host Profiles going into 1.1, I started working to capture some of the information to populate the various fields. At first, I was doing this by hand, but I decided to let Zabbix do it for me. The three bits of data I was most concerned with were MAC Address (Zabbix should really support up to 4 BTW), Linux Distribution, and Linux Kernel Version. To that end, I created the following UserParameter checks that I thought I would share;

UserParameter=custom[oscheck],/usr/bin/head -n1 /etc/redhat-release
UserParameter=custom[kerncheck],/bin/uname -r
UserParameter=custom[macaddr0],/sbin/ifconfig eth0 | /usr/bin/head -n1 | awk '{print $5}'
UserParameter=custom[macaddr1],/sbin/ifconfig eth1 | /usr/bin/head -n1 | awk '{print $5}'
UserParameter=custom[macaddr2],/sbin/ifconfig eth2 | /usr/bin/head -n1 | awk '{print $5}'
UserParameter=custom[macaddr3],/sbin/ifconfig eth3 | /usr/bin/head -n1 | awk '{print $5}'

primos
18-08-2005, 10:50
Nagios check_oracle with Zabbix flavour! copy utils.sh that comes with the official nagios plugins in the same dir as the check! Advise : Make zabbix in the group as oracle (oinstall,dba) client installation(sqlplus):

need: sqlplus,tnsping (make shure zabbix can execute them)
I'm sure this can be improved but a good place to start!

UserParameter=oracletns[db_name],/opt/zabbix/libexec/check_oracle --tns
UserParameter=oracledb[db_name],/opt/zabbix/libexec/check_oracle --db
UserParameter=oraclelogin[db_name],/opt/zabbix/libexec/check_oracle --login
UserParameter=oracletablespace[tablespace_name],/opt/zabbix/libexec/check_oracle --tablespace db_name user user_passwd




-----------------------------------------------------------------------------------------
#! /bin/sh
#
# latigid010@yahoo.com
# 01/06/2000
#
# This Nagios plugin was created to check Oracle status
#

PROGNAME=`basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION=`echo '$Revision: 1.14 $' | sed -e 's/[^0-9.]//g'`

. $PROGPATH/utils.sh


print_usage() {
echo "Usage:"
echo " $PROGNAME --tns <Oracle Sid or Hostname/IP address>"
echo " $PROGNAME --db <ORACLE_SID>"
echo " $PROGNAME --login <ORACLE_SID>"
echo " $PROGNAME --cache <ORACLE_SID> <USER> <PASS> <CRITICAL> <WARNING>"
echo " $PROGNAME --tablespace <ORACLE_SID> <USER> <PASS> <TABLESPACE> <CRITICAL> <WARNING>"
echo " $PROGNAME --oranames <Hostname>"
echo " $PROGNAME --help"
echo " $PROGNAME --version"
}

print_help() {
print_revision $PROGNAME $REVISION
echo ""
print_usage
echo ""
echo "Check Oracle status"
echo ""
echo "--tns SID/IP Address"
echo " Check remote TNS server"
echo "--db SID"
echo " Check local database (search /bin/ps for PMON process) and check"
echo " filesystem for sgadefORACLE_SID.dbf"
echo "--login SID"
echo " Attempt a dummy login and alert if not ORA-01017: invalid username/password"
echo "--cache"
echo " Check local database for library and buffer cache hit ratios"
echo " ---> Requires Oracle user/password and SID specified."
echo " ---> Requires select on v_$sysstat and v_$librarycache"
echo "--tablespace"
echo " Check local database for tablespace capacity in ORACLE_SID"
echo " ---> Requires Oracle user/password specified."
echo " ---> Requires select on dba_data_files and dba_free_space"
echo "--oranames Hostname"
echo " Check remote Oracle Names server"
echo "--help"
echo " Print this help screen"
echo "--version"
echo " Print version and license information"
echo ""
echo "If the plugin doesn't work, check that the ORACLE_HOME environment"
echo "variable is set, that ORACLE_HOME/bin is in your PATH, and the"
echo "tnsnames.ora file is locatable and is properly configured."
echo ""
echo "When checking local database status your ORACLE_SID is case sensitive."
echo ""
echo "If you want to use a default Oracle home, add in your oratab file:"
echo "*:/opt/app/oracle/product/7.3.4:N"
echo ""
support
}

case "$1" in
1)
cmd='--tns'
;;
2)
cmd='--db'
;;
*)
cmd="$1"
;;
esac

# Information options
case "$cmd" in
--help)
print_help
exit $STATE_OK
;;
-h)
print_help
exit $STATE_OK
;;
--version)
print_revision $PLUGIN $REVISION
exit $STATE_OK
;;
-V)
print_revision $PLUGIN $REVISION
exit $STATE_OK
;;
esac

# Hunt down a reasonable ORACLE_HOME
if [ -z "$ORACLE_HOME" ] ; then
# Adjust to taste
for oratab in /var/opt/oracle/oratab /etc/oratab
do
[ ! -f $oratab ] && continue
ORACLE_HOME=`IFS=:
while read SID ORACLE_HOME junk;
do
if [ "$SID" = "$2" -o "$SID" = "*" ] ; then
echo $ORACLE_HOME;
exit;
fi;
done < $oratab`
[ -n "$ORACLE_HOME" ] && break
done
fi
# Last resort
[ -z "$ORACLE_HOME" -a -d $PROGPATH/oracle ] && ORACLE_HOME=$PROGPATH/oracle

if [ -z "$ORACLE_HOME" -o ! -d "$ORACLE_HOME" ] ; then
echo "-1"
exit $STATE_OK
fi
PATH=$PATH:$ORACLE_HOME/bin
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
export ORACLE_HOME PATH LD_LIBRARY_PATH

case "$cmd" in
--tns)
tnschk=` tnsping $2`
tnschk2=` echo $tnschk | grep -c OK`
if [ ${tnschk2} -eq 1 ] ; then
tnschk3=` echo $tnschk | sed -e 's/.*(//' -e 's/).*//'`
echo "${tnschk3}"
exit $STATE_OK
else
echo "-1"
exit $STATE_OK
fi
;;
--db)
pmonchk=`ps -ef | grep -v grep | grep -c "ora_pmon_${2}$"`
if [ ${pmonchk} -ge 1 ] ; then
echo "${pmonchk}"
exit $STATE_OK
#if [ -f $ORACLE_HOME/dbs/sga*${2}* ] ; then
#if [ ${pmonchk} -eq 1 ] ; then
#utime=`ls -la $ORACLE_HOME/dbs/sga*$2* | cut -c 43-55`
#echo "${2} OK - running since ${utime}"
#exit $STATE_OK
#fi
else
echo "0"
exit $STATE_OK
fi
;;
--login)
loginchk=`sqlplus dummy/user@$2 < /dev/null`
loginchk2=` echo $loginchk | grep -c ORA-01017`
if [ ${loginchk2} -eq 1 ] ; then
echo "1"
exit $STATE_OK
else
loginchk3=` echo "$loginchk" | grep "ORA-" | head -1`
echo "0"
exit $STATE_OK
fi
;;

--tablespace)

result=`sqlplus -s ${3}/${4}@${2} << EOF
set pagesize 0
set numf '9999999.99'
select b.free,a.total,100 - trunc(b.free/a.total * 1000) / 10 prc
from (
select tablespace_name,sum(bytes)/1024/1024 total
from dba_data_files group by tablespace_name) A,
( select tablespace_name,sum(bytes)/1024/1024 free
from dba_free_space group by tablespace_name) B
where a.tablespace_name=b.tablespace_name and a.tablespace_name='${5}';
EOF`

if [ -n "`echo $result | grep ORA-`" ] ; then
error=` echo "$result" | grep "ORA-" | head -1`
echo "-1"
exit $STATE_OK
fi

ts_free=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($1)}'`
ts_total=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($2)}'`
ts_pct=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print int($3)}'`
ts_pctx=`echo "$result" | awk '/^[ 0-9\.\t ]+$/ {print $3}'`
if [ "$ts_free" -eq 0 -a "$ts_total" -eq 0 -a "$ts_pct" -eq 0 ] ; then
echo "-1"
exit $STATE_OK
fi

echo "$ts_pctx"
exit $STATE_OK
;;
*)
print_usage
exit $STATE_OK
esac

primos
18-08-2005, 11:41
I would be nice If we would all share our checks and UserParameters here!

Alexei
18-08-2005, 13:06
Please be aware that if you use 1.1 alpha versions you may take advantage of flexible user parameters. It means that instead of:

custom[macaddr0]

you may define

UserParameter=custom
, script.sh

and then use custom[eth0], custom[eth1], custom[whatever]

The parameter will be passed as command line parameter to the script.

primos
18-08-2005, 15:32
Appeal to all to start dumping there own checks here!

primos
18-08-2005, 16:11
Alexei, I've been talking to guys at work, IBM mainframe experts, and they are willing to write a simple agent in kiks. I would really appreciate ANY doc about the protocol that zabbix_agentd uses, to be able to discuss with them further!

primoz@gorkic.com

elkor
18-08-2005, 16:16
I created the following parameters and script to pull individual CPU usage percentages out of top (IO/Wait, Idle, etc.). This helps us determine what exactly the server spends it's time doing and what pieces of code could be optimized to improve it. These parameters are really informative when all placed on the same graph for a given host and looked at over time.

/etc/zabbix/zabbix_agent.conf:
UserParameter=cpupercent[idle],/usr/bin/cat /zabbix/data/CPUusage.idle
UserParameter=cpupercent[user],/usr/bin/cat /zabbix/data/CPUusage.user
UserParameter=cpupercent[iowait],/usr/bin/cat /zabbix/data/CPUusage.iowait
UserParameter=cpupercent[swap],/usr/bin/cat /zabbix/data/CPUusage.swap
UserParameter=cpupercent[kernel],/usr/bin/cat /zabbix/data/CPUusage.kernel

/zabbix/scripts/CPUusage: (run out of cron *****)
#!/bin/ksh
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# Author: Chris Regenye (SysInfrastructure)
# Date: 8/1/2005
# Info: zabbix agent extention to pull values for CPU usage
# breakdown by type. Note: requires top and may need
# modification based on version of top in use.
#
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
rawstates=$(/usr/local/bin/top -d2 | grep "CPU states" | awk '{print $3$4" " $5$6" " $7$8" " $9$10" " $11$12}')
for state in $rawstates
do
integerpercent=${state%.*}
usagetype=${state#*%}
usagetype=${usagetype%,}
echo $integerpercent > /zabbix/data/CPUusage.$usagetype
done
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

marc
24-08-2005, 14:07
Description:
Script checks a Webpage for correct HTTP Return Codes.

Requires:
zabbixX
netcat

Synopsis:
UserParameter=httpd[somename], sh /home/www/zabbix/bin/zabbix-www.sh somename URLtoCheck Port Pagetocheck EstimatedReturnStatus

Example:
UserParameter=httpd[ino],sh /home/www/zabbix/bin/zabbix-www.sh ino www.inotronic.de 80 /home/index.php 200

#!/bin/sh
netcat=/usr/local/bin/nc
VAR=/home/www/zabbix/var

if [ ! -x $netcat ] ; then
echo 42; # netcat not found
exit 42;
fi

request() {
name="$1"
host="$2" # host to check
port="$3" # port to check
uri="$4" # uri to check
code="$5" # expected httpcode

if test -f $VAR/$name.off -o -f $VAR/wwwall.off ; then
echo "-1" # Don't monitor
# (because of maintenance for example)
exit;
fi

RETURN=$(printf 'GET '"$uri"' HTTP/1.1\nHost: '"$host"'\n\nQUIT\n' |
nc -w 5 "$host" "$port" | head -1)

case "$RETURN" in
HTTP/1.[10]" "$code" "*)
echo "0" # good
;;
*)
echo "1"; # Bad
;;
esac
}
request "$@"

morgolis
22-09-2005, 01:09
Wasn't this implemented as a core function in zabbix_agentd? I read through the online manual / documentation for zabbix alpha 1.1 where it shows that you can get this information with the call function: system.cpu.idle1, system.cpu.system1, etc

I created the following parameters and script to pull individual CPU usage percentages out of top (IO/Wait, Idle, etc.). This helps us determine what exactly the server spends it's time doing and what pieces of code could be optimized to improve it. These parameters are really informative when all placed on the same graph for a given host and looked at over time.

/etc/zabbix/zabbix_agent.conf:
UserParameter=cpupercent[idle],/usr/bin/cat /zabbix/data/CPUusage.idle
UserParameter=cpupercent[user],/usr/bin/cat /zabbix/data/CPUusage.user
UserParameter=cpupercent[iowait],/usr/bin/cat /zabbix/data/CPUusage.iowait
UserParameter=cpupercent[swap],/usr/bin/cat /zabbix/data/CPUusage.swap
UserParameter=cpupercent[kernel],/usr/bin/cat /zabbix/data/CPUusage.kernel

/zabbix/scripts/CPUusage: (run out of cron *****)
#!/bin/ksh
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# Author: Chris Regenye (SysInfrastructure)
# Date: 8/1/2005
# Info: zabbix agent extention to pull values for CPU usage
# breakdown by type. Note: requires top and may need
# modification based on version of top in use.
#
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
rawstates=$(/usr/local/bin/top -d2 | grep "CPU states" | awk '{print $3$4" " $5$6" " $7$8" " $9$10" " $11$12}')
for state in $rawstates
do
integerpercent=${state%.*}
usagetype=${state#*%}
usagetype=${usagetype%,}
echo $integerpercent > /zabbix/data/CPUusage.$usagetype
done
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

James Wells
22-09-2005, 01:12
Wasn't this implemented as a core function in zabbix_agentd? I read through the online manual / documentation for zabbix alpha 1.1 where it shows that you can get this information with the call function: system.cpu.idle1, system.cpu.system1, etc
Yup. This capability is now part of the agent as of 1.1beta1. Please note though that Elkor posted this before the capability existed. ;)

elkor
22-09-2005, 15:42
Oh sure morgolis, rain on my parade. thanks a lot ;)

yeah, there is support for this now; although.. I didn't see a built in parameter for I/O wait time on the CPU. For those doing datamining or even backups this can be an important metric.

elkor
22-09-2005, 16:13
A script to set as an action for changes on these items that automatically updates the database with the new values would make the whole thing almost painless....

I haven't looked at the host profiles table yet, but is this feasable?


Greetings,

With the new Host Profiles going into 1.1, I started working to capture some of the information to populate the various fields. At first, I was doing this by hand, but I decided to let Zabbix do it for me. The three bits of data I was most concerned with were MAC Address (Zabbix should really support up to 4 BTW), Linux Distribution, and Linux Kernel Version. To that end, I created the following UserParameter checks that I thought I would share;

UserParameter=custom[oscheck],/usr/bin/head -n1 /etc/redhat-release
UserParameter=custom[kerncheck],/bin/uname -r
UserParameter=custom[macaddr0],/sbin/ifconfig eth0 | /usr/bin/head -n1 | awk '{print $5}'
UserParameter=custom[macaddr1],/sbin/ifconfig eth1 | /usr/bin/head -n1 | awk '{print $5}'
UserParameter=custom[macaddr2],/sbin/ifconfig eth2 | /usr/bin/head -n1 | awk '{print $5}'
UserParameter=custom[macaddr3],/sbin/ifconfig eth3 | /usr/bin/head -n1 | awk '{print $5}'

James Wells
22-09-2005, 17:12
A script to set as an action for changes on these items that automatically updates the database with the new values would make the whole thing almost painless....

I haven't looked at the host profiles table yet, but is this feasable?
Not yet, no, however, this is another thing that I plan to create a patch for. At present, the way I am doing it is using the checks listed previously then doing a simple SQL comand to copy the values I want over to the hosts_profiles table. What I have completed of the hosts_profiles so far, automatically updates the hosts_profiles MAC[0-3] addresses, pulls the machines physical memory for to set the limits on various memory usage graphs, pulls the MAC[0-4] addresses-to-Hostname for use in the network bandiwdth and usage graphs from my switches, auto generates maps which show every server in a 19inch rack, and also generates BTU / AMP / Watt reports for capacity planning. ;)

Unfortunately, I just had to take my development machine into the shop, so my ability to turn all of this stuff into a patch against the current system is severely limited right now. :(

Alexei
22-09-2005, 17:17
FYI I plan to enhance functionality of host profiles to allow usage of macros. So, most of information displayed in host profiles will be collected by ZABBIX (SNMP, whatever) agents.

elkor
22-09-2005, 18:24
pulls the machines physical memory for to set the limits on various memory usage graphs, pulls the MAC[0-4] addresses-to-Hostname for use in the network bandiwdth and usage graphs from my switches, auto generates maps which show every server in a 19inch rack, and also generates BTU / AMP / Watt reports for capacity planning. ;)
That sounds great dude! the autogeneration of server racks along with the cap planning info in particular sounds like quite a bit of work, I'd definately be interested in seeing what you have even if it was just a tarball of the existing files from the alpha build, I have the originals so I could run the diffs here. that could really open up some new functionality for me.

The memory graph ceiling is also a killer idea, my plan was just to put the total memory on the graph and set it to autosize but this would remove one item from each graph (haven't done mem graphs yet as I'm still in rollout here and they are looking for "Wow factor" and mem graphs tend to be a bit flat for most of my servers)

Unfortunately, I just had to take my development machine into the shop, so my ability to turn all of this stuff into a patch against the current system is severely limited right now. :(
well that's no good. here's to hoping you get your playground back soon.

James Wells
22-09-2005, 19:08
I'd definately be interested in seeing what you have even if it was just a tarball of the existing files from the alpha build, I have the originals so I could run the diffs here. that could really open up some new functionality for me.
Will get them to you as soon as I get my development machine back. Sadly, that is the only place I have them at present. :(

elkor
22-09-2005, 20:20
FYI I plan to enhance functionality of host profiles to allow usage of macros. So, most of information displayed in host profiles will be collected by ZABBIX (SNMP, whatever) agents.

Excellent Alexei, I'll hold off on doing anything manually then. any idea about a timeframe? I know you get asked that a lot, just curious.

elkor
22-09-2005, 20:21
Will get them to you as soon as I get my development machine back. Sadly, that is the only place I have them at present. :(

many thanks, I look forward to seeing it!

Nate Bell
13-12-2005, 17:15
Wasn't this implemented as a core function in zabbix_agentd? I read through the online manual / documentation for zabbix alpha 1.1 where it shows that you can get this information with the call function: system.cpu.idle1, system.cpu.system1, etc

I've had some problems getting this one to work properly. It's reporting a value for each CPU time I check, but the value never changes. Could someone who got this working tell me what settings they used?
Thanks,
Nate

sysigs
04-10-2006, 10:50
Hello,
I made an evolution of oracle script and using it from Windows
UserParameter=oralog[O8IF],C:\zabbix_agent\External\oracle.cmd login O8IF
UserParameter=orats3[ANNUAIRE],C:\zabbix\External\oracle.cmd ts3 O8IF dummy user ANNUAIRE
UserParameter=oratsc[O8IF],C:\zabbix\External\oracle.cmd tscount O8IF dummy user

-> oracle.cmd
@echo Off
set Header="oracle.cmd 1.0 2006/03/07 12:12:00"
rem +================================================= ==========================+
rem | Copyright (c) 2004 THALES Information Systems Site de Sophia, FRANCE |
rem | All rights reserved |
rem | Applications Division |
rem +================================================= ==========================+
rem |
rem | FILENAME
rem | oracle.cmd
rem |
rem | DESCRIPTION
rem | Procedure de test base oracle pour ZABBIX
rem |
rem | USAGE
rem | oracle.cmd [login|tsx|tscount|help|version]
rem | login <ORACLE_SID>
rem | tscount <ORACLE_SID> <USER> <PASS>
rem | ts1 <ORACLE_SID> <USER> <PASS> <TABLESPACE> <CRITICAL> <WARNING>
rem | ts2 <ORACLE_SID> <USER> <PASS> <TABLESPACE> <CRITICAL> <WARNING>
rem | ts3 <ORACLE_SID> <USER> <PASS> <TABLESPACE> <CRITICAL> <WARNING>
rem | help
rem | version
rem |
rem | EXEMPLE
rem | oracle.cmd version
rem |
rem | PLATFORM
rem | WinNt
rem |
rem | NOTES
rem |
rem | HISTORY
rem |
rem +================================================= ==========================+

set PROGNAME=oracle.cmd
set PROGPATH=c:\zabbix\external
set REVISION=1.0
call %PROGPATH%\_Init.cmd
@echo OFF

IF "V%1"=="V" call :usage
cd %PROGTEMP%
IF "%1"=="help" call :help
IF "%1"=="HELP" call :help

IF "%1"=="login" call :login %2
IF "%1"=="LOGIN" call :login %2

IF "%1"=="tscount" call :tscount %2 %3 %4
IF "%1"=="TSCOUNT" call :tscount %2 %3 %4

IF "%1"=="TS1" call :ts1 %2 %3 %4 %5
IF "%1"=="ts1" call :ts1 %2 %3 %4 %5

IF "%1"=="TS2" call :ts2 %2 %3 %4 %5
IF "%1"=="ts2" call :ts2 %2 %3 %4 %5

IF "%1"=="TS3" call :ts3 %2 %3 %4 %5
IF "%1"=="ts3" call :ts3 %2 %3 %4 %5

IF "%1"=="version" call :version
IF "%1"=="VERSION" call :version
goto fin

:usage
echo "Usage:"
echo " %PROGNAME% login <ORACLE_SID>"
echo " %PROGNAME% ts1 <ORACLE_SID> <USER> <PASS> <TABLESPACE> <CRITICAL> <WARNING>"
echo " %PROGNAME% ts2 <ORACLE_SID> <USER> <PASS> <TABLESPACE> <CRITICAL> <WARNING>"
echo " %PROGNAME% ts3 <ORACLE_SID> <USER> <PASS> <TABLESPACE> <CRITICAL> <WARNING"
echo " %PROGNAME% tscount <ORACLE_SID> <USER> <PASS>"
echo " %PROGNAME% help"
echo " %PROGNAME% version"
goto :EOF

:help
echo %PROGNAME% %REVISION%
echo ""
call :usage
echo ""
echo " Test Oracle status"
echo ""
echo "tns SID/IP Address"
echo " Check remote TNS server"
echo ""
echo "login SID"
echo " Tente une connection dummy login et previent si pas 'ORA-01017: invalid username/password'"
echo ""
echo "ts1 ts2 ou ts3"
echo " Test database locale pour la taille du tablespace dans ORACLE_SID"
echo " ---> Requier Oracle user/password specifique."
echo " ---> Requier 'select' sur 'dba_data_files' et 'dba_free_space'"
echo " ---> ts1 recupere la place restante"
echo " ---> ts2 recupere la taille totale"
echo " ---> ts3 recupere le pourcentage d'occupation"
echo ""
echo "tscount"
echo " Evalue dans une database locale pour le nombre de tablespace dans ORACLE_SID"
echo " ---> Requier Oracle user/password specifique."
echo " ---> Requier 'select' sur 'dba_object'"
echo ""
echo "help"
echo " Affiche cet ecran de Help"
echo ""
echo "version"
echo " Affiche la version et la license"
echo ""
echo "Attention l'ORACLE_SID est 'case sensitive'."
echo ""
echo ""
goto :EOF


:version
echo %PLUGIN% %REVISION%
goto :EOF


:login
set BASEORACLE=%1
%ORACLE_HOME%\bin\sqlplus /nolog @%PROGSQL%\exit.sql %BASEORACLE% > %PROGTEMP%\Login_%BASEORACLE%.log
set retour=%ERRORLEVEL%
%PROGPATH%\printf %retour%
goto :EOF

:ts1
call :ts %1 %2 %3 %4
for /F "tokens=1 delims=. " %%a in ('echo %ts_free%') do set ts_free=%%a
%PROGPATH%\printf %ts_free%
goto :EOF
:ts2
call :ts %1 %2 %3 %4
for /F "tokens=1 delims=. " %%a in ('echo %ts_total%') do set ts_total=%%a
%PROGPATH%\printf %ts_total%
goto :EOF
:ts3
call :ts %1 %2 %3 %4
for /F "tokens=1 delims=. " %%a in ('echo %ts_pct%') do set ts_pct=%%a
%PROGPATH%\printf %ts_pct%
goto :EOF

:ts
set ts_free=0
set ts_total=0
set ts_pct=0
set BASEORACLE=%1
set tbsp=%4

set file=%PROGTEMP%\tablespace_%BASEORACLE%_%tbsp%.lis
%ORACLE_HOME%\bin\sqlplus -s %2/%3@%BASEORACLE% @%PROGSQL%\tablespace.sql %tbsp% > %file%
set retour=%ERRORLEVEL%
for /F "tokens=1,2,3" %%a in (%file%) do call :extract_ts %%a %%b %%c

del %file% > nul
goto :EOF

:extract_ts
if "%ts_free%"=="0" set ts_free=%1
if "%ts_total%"=="0" set ts_total=%2
if "%ts_pct%"=="0" set ts_pct=%3
goto :EOF

:tscount
set ts_count=0
set BASEORACLE=%1
set file=%PROGTEMP%\tablespace_%BASEORACLE%.lis

%ORACLE_HOME%\bin\sqlplus -s %2/%3@%BASEORACLE% @%PROGSQL%\tscount.sql > %file%
set retour=%ERRORLEVEL%
for /F "tokens=1 " %%a in (%file%) do call :ext_tsc %%a
%PROGPATH%\printf %ts_count%
del %file% > nul

goto :EOF

:ext_tsc
if "%ts_count%"=="0" set ts_count=%1
goto :EOF

:fin

-> _init.cmd
@echo Off
set PROGTEMP=C:\temp
set PROGSQL=%PROGPATH%\sql
set ORACLE_HOME=D:\oracle\ora81

-> exit.sql
WHENEVER SQLERROR EXIT FAILURE ROLLBACK;
SET VERIFY OFF
WHENEVER OSERROR EXIT FAILURE ROLLBACK;
connect dummy/user@&1
exit

-> tablespace.sql
WHENEVER SQLERROR EXIT FAILURE ROLLBACK;
SET VERIFY OFF
WHENEVER OSERROR EXIT FAILURE ROLLBACK;
set pagesize 0
set numf '9999999.99'
select b.free,a.total,100 - trunc(b.free/a.total * 1000) / 10 prc
from
(select tablespace_name,sum(bytes)/1024/1024 total
from dba_data_files group by tablespace_name) A,
( select tablespace_name,sum(bytes)/1024/1024 free
from dba_free_space group by tablespace_name) B
where a.tablespace_name=b.tablespace_name and a.tablespace_name='&1';
exit

-> TsCount.sql
WHENEVER SQLERROR EXIT FAILURE ROLLBACK;
SET VERIFY OFF
WHENEVER OSERROR EXIT FAILURE ROLLBACK;
set pagesize 0
set numf '9999999'
select count(*)
from dba_tablespaces;
exit

Nagios check_oracle with Zabbix flavour! copy utils.sh that comes with the official nagios plugins in the same dir as the check! Advise : Make zabbix in the group as oracle (oinstall,dba) client installation(sqlplus):

need: sqlplus,tnsping (make shure zabbix can execute them)
I'm sure this can be improved but a good place to start!

UserParameter=oracletns[db_name],/opt/zabbix/libexec/check_oracle --tns
UserParameter=oracledb[db_name],/opt/zabbix/libexec/check_oracle --db
UserParameter=oraclelogin[db_name],/opt/zabbix/libexec/check_oracle --login
UserParameter=oracletablespace[tablespace_name],/opt/zabbix/libexec/check_oracle --tablespace db_name user user_passwd

.../...

esac

colin7151
17-11-2006, 00:08
Excellent Alexei, I'll hold off on doing anything manually then. any idea about a timeframe? I know you get asked that a lot, just curious.

I agree this sounds wonderful, I can not wait for this to appear, as it could greatly enhance the usefulness of zabbix for my company.

I am currently trying to fend off a push from our helpdesk to put there goofy inventory software on our servers, this feature could put an end to there requests promptly.

Any indication as to when this might appear ?

richlv
27-12-2006, 16:40
Please be aware that if you use 1.1 alpha versions you may take advantage of flexible user parameters. It means that instead of:

custom[macaddr0]

you may define

UserParameter=custom
, script.sh

and then use custom[eth0], custom[eth1], custom[whatever]

The parameter will be passed as command line parameter to the script.

well, in case anybody else stumbles upon this ;)
syntax has changed (http://www.zabbix.com/forum/showthread.php?t=1755), so you have to note parameters like this :
UserParameter=hpasm ,/home/zabbix/bin/hpasmwrapper $1 $2 $3

if you have differing parameter count, just pass as many parameters as the largest command (for example, the script works with one or two parameters).
the key would be
hpasm[temperature cpu 1]
or
hpasm[temperature,io]
- both spaces and commas work for parameter separation (though i haven't tested whether this would work with reverse order or additional characters - commas probably would be safer).

if you want to pass parameters in different order or with additional control characters/options, do as in the linked example -
UserParameter=whatever ,/usr/local/bin/command $3 --$2 -o $1