Tikejhya: Ashish Nepal

Knowledgebase

Category: Zabbix

zabbix time based triggers

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

Zabbix time based triggers:

Flapping proof and time based triggers on zabbix

Server {HOSTNAME} is unreachable ({ashishnepal.com:agent.ping.nodata(480)}=1|({TRIGGER.VALUE}=1)&({ashishnepal.com:agent.ping.count(480)}<4))&({ashishnepal.com:agent.ping.time(0)}>073000&{ashishnepal.com:agent.ping.time(0)}<180000) In above example: trigger would only fire if: trigger value is not in trigger & ping responded with no data for 4 Minutes, ping count was less than 4 for same period of time and if time is between 7:30 to 18:00 hour. e.g 2: If server was restarted but not between certain time: {HOSTNAME} has just been restarted: {ashishnepal.com:system.uptime.last(0)}<600&({ashishnepal.com:system.uptime.time(0)}<180000&{ashishnepal.com:system.uptime.time(0)}>073000)

creating zabbix parameters (quick & easy)

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

#!/bin/bash

LOGFILE=`find /application/log/*/ -name “*-20??-??-??” | grep -i ‘[a-zA-Z]-[0-9]’`

for i in $LOGFILE; do

LOGNAME=`basename $i`
KEY=`basename $i | sed ‘s/………..$//g’`
LOGFULLNAME=`echo “${i}” | sed ‘s/………..$//g’`

echo “UserParameter=app.${KEY},wc -l ${LOGFULLNAME}-`date +%Y-%m-%d` | awk ‘{print $1}'”

KEYTONAME=`echo “$KEY” | sed ‘s/_/ /g’`

HOSTID=’10080’
KEY=bidsys.${KEY}
NAME=$KEYTONAME
DELAY=120

echo “INSERT INTO items (‘hostid’, ‘name’, ‘key_’, ‘delay’) VALUES (‘$HOSTID’, ‘$NAME’, ‘$KEY’, ‘$DELAY’);”

done

Zabbix Installation in CENTOS

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

While installating zabbix in centos there could be below given problems (May occur.)

Zabbix installation in CENTOS

checking for IKSEMEL... no
configure: error: Jabber library not found

solution : yum install iksemel-devel

Missing XMLWriter

yum install php-xml

checking for net-snmp-config... no
configure: error: Invalid NET-SNMP directory - unable to find net-snmp-config

yum install net-snmp-devel

yum install php-bcmath

PHP MB string	yes	 	 	Ok
if fail : isntall php-mbstring
could you face problem from php.ini

need to fix, date.timezone = "Europe/London"

default zabbix username and password for login is
Admin and password blank.

however if that creates problem.
update password,

USE zabbix;
UPDATE users SET passwd=md5(‘newpassword’) WHERE alias=’Admin’;

How to setup zabbix_proxy

Name: ashish.nepal.com
Groups : (Any wished)
DNS name : this should be same as Name, hostname in /zabbix_agentd.conf (in agent)
IP address : local ip (which is corresponding by proxy server)
monitored by proxy : proxy server name (should be in drop down).

/etc/zabbix/zabbix_agentd.conf

Hostname=same name as DNS name and name of server in GUI (Front end)
Server=internalip,zabbix_serverip

How to create trigger for Mysql Replication status in Zabbix

Show how many minutes slave is lagging behind Master

UserParameter=give.some.name,mysql -uzabbix -ppassword -e "SHOW SLAVE STATUSG" | grep Behind | cut -d ":" -f 2

Show if Slave sql is running Or Not

UserParameter=mysql.slave.lag,mysql -uzabbix -ppassword -e 'show slave statusG' | grep Slave_SQL_Running | awk '{print $2}' | sed 's/No/0/;s/Yes/1/'

How to Allow zabbix User to monitor rabbitmqctl

Userparameter to be added in rabbitmq server which is zabbix_agentd

vi /etc/zabbix/zabbix_agentd.conf

UserParameter should look like this if not exact.

UserParameter=mess.message.ready,sudo /usr/sbin/rabbitmqctl -n rabbit@servername list_queues name messages_ready | grep 'which-queue' | awk '{ print $2 }'
UserParameter=mess.queues.messages,sudo /usr/sbin/rabbitmqctl -n rabbit@servername list_queues name messages | grep 'which-queue' | awk '{ print $2 }'
UserParameter=mess.queues.memory,sudo /usr/sbin/rabbitmqctl -n rabbit@servername list_queues name messages | grep 'which-queue' | awk '{ print $2 }'

You would probably recieve error , as sudo is only allowed in TTY, if not using sudo, it would yeild Permission denied.

how to add user in sudo
visudo

%zabbix ALL=(ALL) NOPASSWD: /usr/sbin/rabbitmqctl
Defaults:%zabbix !requiretty
Defaults:zabbix !requiretty

(This is allow Default requiretty to exclude in for given senario)

cannot recreate Zabbix semaphores for IPC key

zabbix_agentd [8394]: Can’t recreate Zabbix semaphores for IPC key 0x7a028449 Semaphore ID 196608. Operation not permitted.

You should check ipcs and kill those with below given command, where it may vary, as awk $3 is username in the given senario

ipcs -s | awk ' $3 == "507" {print $2, $3}' | awk '{ print $1}' | while read i; do ipcrm sem $i; done

And you should restart rabbitmq-server and ctl, which might prompt you to node rabbit@….

Other useful parameter would be [RABBITMQ]

rabbitmqctl -n rabbit@server list_queues | grep -cv '...'
rabbitmqctl -n rabbit@server list_exchanges | grep -cv '...'
rabbitmqctl -n rabbit@server list_queues name durable | awk '{ print $2 }'
rabbitmqctl -n rabbit@server list_queues name messages_ready | awk '{ print $2 }'
rabbitmqctl -n rabbit@server list_queues name messages_unacknowledged | awk '{ print $2 }'
rabbitmqctl -n rabbit@server list_queues name messages | awk '{ print $2 }'
rabbitmqctl -n rabbit@server list_queues name consumers | awk '{ print $2 }'
rabbitmqctl -n rabbit@server list_queues name memory | awk '{ print $2 }'
rabbitmqctl -n rabbit@server list_exchanges name durable | awk '{ print $2 }'
rabbitmqctl -n rabbit@server list_exchanges name type | awk '{ print $2 }'

Memcached Monitoring using zabbix

UserParameter=memcached.stat.,echo -e "statsnquit" | nc 127.0.0.1 11211 | grep "STAT $2 " | awk '{print $$3}'
memcache.curr.connection,echo -e "statsnquit" | nc 127.0.0.1 11211 | grep "STAT $2" | grep "curr_connections" | awk '{print $3}'

Zabbix Real Time Data Log Count

Zabbix Log count Does not provide the real time output by simply doing tail with pipe command, however counting log file and simply gathering the change of number would provide accurate data.

wc -l logfile

And in zabbix UI, count as delta (simple change).

###########################################################

Script to write Userparameter In zabbix (Automated Script)

###########################################################

#!/bin/bash
rm -f /etc/zabbix/backup/zabbix_agentd.conf.*
cp /etc/zabbix/zabbix_agentd.conf /etc/zabbix/backup/zabbix_agentd.conf.`date +%s`
VAR=`grep -w "# Include=/etc/zabbix/zabbix_agentd.userparams.conf" /etc/zabbix/zabbix_agentd.conf`
RETVAL=$?
[ $RETVAL -eq 0 ] && sed -i 's/# Include=/etc/zabbix/zabbix_agentd.userparams.conf/ Include=/etc/zabbix/zabbix_agentd.userparams.conf/g' /etc/zabbix/zabbix_agentd.conf

RETVAL=$?
echo "$RETVAL"

echo "now"

if [ -f "/etc/zabbix/zabbix_agentd.userparams.conf" ]; then
    echo "User parameter File exists"


rm -f /etc/zabbix/backup/zabbix_agentd.userparams.conf.*
cp /etc/zabbix/zabbix_agentd.userparams.conf /etc/zabbix/backup/zabbix_agentd.userparams.conf.`date +%s`
echo "Userparameter=$1,$2" >> /etc/zabbix/zabbix_agentd.userparams.conf


else
        echo "There isnt any Userparameter.conf : Creating File"
                touch /etc/zabbix/zabbix_agentd.userparams.conf
                chown zabbix:zabbix /etc/zabbix/zabbix_agentd.userparams.conf

fi

zabbix parameter (howto get inventory)

[root@tikejhya~]# zabbix_get -s www.tikejhya.com -p 10050 -k “system.hw.cpu”
processor 0: GenuineIntel Intel(R) Xeon(R) CPU X5650 @ 2.67GHz working at 2666MHz

[root@tikejhya~]# zabbix_get -s www.tikejhya.com -p 10050 -k “system.hw.macaddr[eth1]”
[eth1] 00:50:56:01:03:81

[root@tikejhya~]# zabbix_get -s www.tikejhya.com -p 10050 -k “system.sw.os[full]”
Linux version 2.6.32-220.7.1.el6.x86_64 (mockbuild@c6b18n3.bsys.dev.centos.org) (gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC) ) #1 SMP Wed Mar 7 00:52:02 GMT 2012

[root@tikejhya~]# zabbix_get -s www.tikejhya.com -p 10050 -k “system.sw.os[name]”
CentOS Linux release 6.0 (Final)

[root@tikejhya~]# zabbix_get -s www.tikejhya.com -p 10050 -k “system.sw.packages[yum]”
[rpm] yum-3.2.27-14.el6.centos.noarch, yum-metadata-parser-1.1.2-14.1.el6.x86_64, yum-plugin-fastestmirror-1.1.26-11.el6.noarch

[root@tikejhya~]# zabbix_get -s www.tikejhya.com -p 10050 -k “system.sw.packages[httpd]”
[rpm] httpd-2.2.15-15.el6.centos.1.x86_64, httpd-tools-2.2.15-15.el6.centos.1.x86_64

[root@tikejhya~]# zabbix_get -s www.tikejhya.com -p 10050 -k “system.sw.packages[mysql|httpd]”
[rpm] httpd-2.2.15-15.el6.centos.1.x86_64, httpd-tools-2.2.15-15.el6.centos.1.x86_64, mysql-5.1.61-1.el6_2.1.x86_64, mysql-devel-5.1.61-1.el6_2.1.x86_64, mysql-libs-5.1.61-1.el6_2.1.x86_64, mysql-server-5.1.61-1.el6_2.1.x86_64, php-mysql-5.3.3-3.el6_2.6.x86_64

[root@tikejhya~]# zabbix_get -s www.tikejhya.com -p 10050 -k “system.sw.arch”
x86_64

Installing Skype on Linux (centos 5.6) and sending message using zabbix

Subject itself sounds crazy, yet intresting.

Installing Skype on Linux (centos 5.6) and sending message using zabbix

Installing skype on Linux 5.6
Installing skype 2.2 on linux 6.2 is easy peasy 😀

Download static version of skype for linux, if you are installing skype on linux 5.6 you better pick, older skype version

Download skype of version that suits you.
skype_static-2.1.0.81.tar
skypeAPI (Skype4Py – i have been using 1.0.31.0)

Skype would need to install either GUI or Use vnc server in order to be able to accept terms and condition (checkbox) and to accept skypeAPI integration.

1) If you follow to do with GUI (easiest just install KDE, GNOME according to your suit and install x windows)

2) If you follow to do with VNC (you would need to install Xvfb, fluxbox, x11vnc, dbus and modules according to need all problem i faced during the process is mentioned below).

Simply extract skype_static tarball and cp skype to /usr/bin/skype.

Install skype4Py with following command:

cd Skype4Py-1.0.31.0/
python setup.py install

Implementing skype on zabbix to send message

You will need to setup Media type and user profile.
which is pretty much simple for those user who has used zabbix.
And Action on configuration, which will define how to treat on alert and choose skype and user to alert.

with the given script (sendim.sh and sendim.py)

skype message on the server as skype user: ./sendim.sh ‘tikejhya’ ‘test this’

Script:
Sendim.sh

#!/bin/bash
DISPLAY=localhost:0.0
export DISPLAY
my_arg="${@:2:6}"
python ./sendim.py "$1" "$my_arg"

[Note: I used Display localhost to ensure tranporting display which can be in bash_profile]
[Note: Zabbix sends message as script username message so i wanted to use all message apart from username
this will allow you to send multiple macros.]

./sendim.py

import Skype4Py
import sys

# Create an instance of the Skype class.
skype = Skype4Py.Skype()

# Connect the Skype object to the Skype client.
skype.Attach()
user = sys.argv[1]
msg = ' '.join(sys.argv[2:])
message = skype.SendMessage(user, msg)

[This script imports skype4py which you might have installed already in above given tips.]

./skype_login.sh

#!/bin/bash
echo tikejhya password | skype --pipelogin&

[this is how you can login to skype from CLI]

Did i miss anything?

This link was really helpful to get me going
http://www.qxs.ch/2011/01/07/skype-instant-messages-from-zabbix/

###########################################################
Problem i faced during installation.

Install Skype in EL6

yum install skype

If you do not have my repo installed:

wget http://li.nux.ro/download/nux/dextop/el6/x86_64/skype-2.2.0.35-3.el6.nux.i586.rpm
yum localinstall --nogpgcheck ./skype-2.2.0.35-3.el6.nux.i586.rpm

All of the above needs to be done as root, obviously.

#############################################################

rpm -Uvh http://ftp.ntua.gr/pub/linux/fedora-epel/6/x86_64/epel-release-6-6.noarch.rpm

(if unable to open web, and search for which epel-release version is available)

yum install wine

############################################################

/usr/bin/python2.5: bad interpreter: No such file or directory

To get around this, open skysentials.py with your favourite text editor and change the very first line from:

  #!/usr/bin/python2.5

to:

#!/usr/bin/python

###########################################################

Changing dbus to x11 (BTW you dont need to change build one but compile again)

vi skype4py/build/lib/Skype4Py/api/posix.py	
vi skype4py/Skype4Py/api/posix.py

def SkypeAPI(opts):
trans = opts.pop(‘Transport’, ‘x11’)
if trans == ‘dbus’:
from posix_dbus import SkypeAPI
elif trans == ‘x11’:
from posix_x11 import SkypeAPI
else:
raise SkypeAPIError(‘Unknown transport: %s’ % trans)
############################################################

How to setup Skype headless on centos 5.6

Download Skype Static Package version:
skype_static-2.1.0.81.tar

tar -xvf skype_static-2.1.0.81.tar
cd skype_static-2.1.0.81

############################################################
Problem: libstdc++ GLIBC error
Solution: Older Skype version
############################################################

[root@ashishnepal Skype4Py-1.0.32.0]# Xvfb :1 -screen 0 800x600x24
Couldn’t open RGB_DB ‘/usr/share/X11/rgb’
_XSERVTransSocketOpenCOTSServer: Unable to open socket for inet6
_XSERVTransOpen: transport open failed for inet6/ashishnepal:1
_XSERVTransMakeAllCOTSServerListeners: failed to open listener for inet6
error opening security policy file /usr/lib64/xserver/SecurityPolicy
Could not init font path element unix/:7100, removing from list!
FreeFontPath: FPE “built-ins” refcount is 2, should be 1; fixing.

solution: Comment out ipv6 , disable = 1

[root@ashishnepal Skype4Py]# cat /etc/modprobe.conf
alias scsi_hostadapter mptbase
alias scsi_hostadapter1 mptspi
alias scsi_hostadapter2 ata_piix
alias net-pf-10 off
# alias ipv6 off
# options ipv6 disable=1
# Added by VMware Tools
install pciehp /sbin/modprobe -q --ignore-install acpiphp; /bin/true
install pcnet32 (/sbin/modprobe -q --ignore-install vmxnet || /sbin/modprobe -q --ignore-install pcnet32 $CMDLINE_OPTS);/bin/true
alias eth0 e1000

###########################################################

Xvfb :1 -screen 0 800x600x24

export Display
DISPLAY=localhost:0.0
export DISPLAY

Pipe Login.
echo tikejhya Password | skype --pipelogin

###########################################################
If you are willing to run zabbix in diff server and have centos with skype in diff server this may totally make sense.

sudo: no tty present and no askpass program specified

# %users  localhost=/sbin/shutdown -h now
%tikejhya    ALL=(ALL)      NOPASSWD: ALL

#########################################################
[root@ashishnepal skype4py]# sudo /root/sendim.sh tikejhya “Ok this is it”
Xlib: connection to “localhost:0.0” refused by server
Xlib: No protocol specified

Traceback (most recent call last):
File “/root/sendim.py”, line 4, in ?
skype = Skype4Py.Skype()
File “/usr/lib/python2.4/site-packages/Skype4Py/skype.py”, line 250, in __init__
self._Api = SkypeAPI(Options)
File “/usr/lib/python2.4/site-packages/Skype4Py/api/posix.py”, line 40, in SkypeAPI
return SkypeAPI(opts)
File “/usr/lib/python2.4/site-packages/Skype4Py/api/posix_x11.py”, line 254, in __init__
raise SkypeAPIError(‘Could not open XDisplay’)
Skype4Py.errors.SkypeAPIError: Could not open XDisplay
/root/sendim.sh: line 6: 5816 Segmentation fault python /root/sendim.py “$1” “$2”

Solution:

[root@ashishnepal skype4py]# su -
[root@ashishnepal ~]# /root/sendim.sh tikejhya "Ok this is it"

[environmental variable plus exporting display is sometimes tricky]

Also if you want to make more certain

[root@ashishnepal.com Skype4Py]# echo tikejhya password | skype –pipelogin
Xlib: connection to “localhost:0.0” refused by server
Xlib: No protocol specified

this is becuase of .xauthority file…

su –
and it should be fine…

or need to find way to use .xauthority file..

/usr/bin/mkxauth [-q] [-u ] -m 

-u     create/merge .Xauthority for user 

Best practice: mkxauth -u skype -m root

###############################################################
skype not snyncing

http://www.mydigitallife.info/how-to-disable-upnp-in-skype-to-remove-open-tcp-and-udp-ports-in-firewall/
Its all in all upnp play.
###############################################################

Debugging shell script arguments.

While implementing skype in zabbix we normally dont see any logs so it was important for me to see weather message were being passed or not.

Simple script.

#!/bin/bash
KEY="/home/zabbix/id_rsa"
PORT=2222
USER="skype@ashishnepal.com"
SCRIPT="/home/skype/sendim.sh"
# my_arg="${@:2:6}"

echo "..............">>skypelog.txt

echo "Total Arguments: $#" >> skypelog.txt
i=1;
echo ".........................">>skypelog.txt
for var in "$@"
        do
          echo "Argument $i is $var" >> skypelog.txt
          let i=$i+1;
        done

ssh -p${PORT} -i $KEY $USER "$SCRIPT "$1" "$2""

Delay on message arrival : Firewall
Skype message not delivered yet?

Allways allow from the SKYPEAPI Server IP (from port) 1024 (to port) 65535.

This should solve issue.

##########################################################

GUI for sending skype message

Sending Skype Message from Web:





Script to write Userparameter In zabbix

(Automated Script)

#!/bin/bash
rm -f /etc/zabbix/backup/zabbix_agentd.conf.*
cp /etc/zabbix/zabbix_agentd.conf /etc/zabbix/backup/zabbix_agentd.conf.`date +%s`
VAR=`grep -w "# Include=/etc/zabbix/zabbix_agentd.userparams.conf" /etc/zabbix/zabbix_agentd.conf`
RETVAL=$?
[ $RETVAL -eq 0 ] && sed -i 's/# Include=/etc/zabbix/zabbix_agentd.userparams.conf/ Include=/etc/zabbix/zabbix_agentd.userparams.conf/g' /etc/zabbix/zabbix_agentd.conf

RETVAL=$?
echo "$RETVAL"

echo "now"

if [ -f "/etc/zabbix/zabbix_agentd.userparams.conf" ]; then
    echo "User parameter File exists"


rm -f /etc/zabbix/backup/zabbix_agentd.userparams.conf.*
cp /etc/zabbix/zabbix_agentd.userparams.conf /etc/zabbix/backup/zabbix_agentd.userparams.conf.`date +%s`
echo "Userparameter=$1,$2" >> /etc/zabbix/zabbix_agentd.userparams.conf


else
        echo "There isnt any Userparameter.conf : Creating File"
                touch /etc/zabbix/zabbix_agentd.userparams.conf
                chown zabbix:zabbix /etc/zabbix/zabbix_agentd.userparams.conf

fi

Powered by WordPress & Theme by Anders Norén