lost and found ( for me ? )

how to install / use libvirt-snmp on CentOS6

libvirt-snmp allows you to get KVM-related info via snmpget , snmptrap.
Add to that , you can shutdown , pause , start VMs via snmpset.
Here’s an explanation of how to install / use libvirt-snmp.

I just referred to http://wiki.libvirt.org/page/Libvirt-snmp#libvirt-snmp.
many thanks!

# uname –ri
2.6.32-279.19.1.el6.x86_64 x86_64

# cat /etc/centos-release
CentOS release 6.3 (Final)

# /usr/libexec/qemu-kvm --version
QEMU PC emulator version 0.12.1 (qemu-kvm-0.12.1.2), Copyright (c) 2003-2008 Fabrice Bellard

# libvirtd --version
libvirtd (libvirt) 0.9.10


[ installation logs of libvirt-snmp including trial and error ]

download libvirt-snmp via git
# git clone git://libvirt.org/libvirt-snmp.git

# ls libvirt-snmp/
AUTHORS  INSTALL.1st  NEWS    autobuild.sh  configure.ac  libvirt-snmp.spec.in
COPYING  Makefile.am  README  autogen.sh    docs          src


install some packages which are required to build libvirt-snmp.
# yum install net-snmp-perl net-snmp net-snmp-utils net-snmp-devel libvirt-devel rpm-build -y


build libvirt-snmp
# cd libvirt-snmp/

# ./autobuild.sh

test -n "$1" && RESULTS=$1 || RESULTS=results.log
: ${AUTOBUILD_INSTALL_ROOT=$HOME/builder}

# Make things clean.
test -f Makefile && make -k distclean || :

rm -rf build
mkdir build
cd build

MIBDIR=$AUTOBUILD_INSTALL_ROOT/share/snmp/mibs
mkdir -p $MIBDIR

../autogen.sh --prefix=$AUTOBUILD_INSTALL_ROOT \
 --with-mibdir=$MIBDIR
../autogen.sh: line 22: autoreconf: command not found


need autoreconf command to build libvirt-snmp. install autoreconf via yum.
# yum install -y autoconf


run autobuild.sh again.
nn , error
# ./autobuild.sh

test -n "$1" && RESULTS=$1 || RESULTS=results.log
: ${AUTOBUILD_INSTALL_ROOT=$HOME/builder}

# Make things clean.
test -f Makefile && make -k distclean || :

rm -rf build
mkdir build
cd build

MIBDIR=$AUTOBUILD_INSTALL_ROOT/share/snmp/mibs
mkdir -p $MIBDIR

../autogen.sh --prefix=$AUTOBUILD_INSTALL_ROOT \
 --with-mibdir=$MIBDIR
Can't exec "aclocal": No such file or directory at /usr/share/autoconf/Autom4te/FileUtils.pm line 326.
autoreconf: failed to run aclocal: No such file or directory


I googled this error and this might be solved by installing automake.
install automake
# yum install automake –y


try again. okay.
# ./autobuild.sh
<snip>
Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-snmp-0.0.3-1.el6.root1358398204.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.Sd7MN0
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd libvirt-snmp-0.0.3
+ /bin/rm -rf /root/rpmbuild/BUILDROOT/libvirt-snmp-0.0.3-1.el6.root1358398204.x86_64
+ exit 0
Executing(--clean): /bin/sh -e /var/tmp/rpm-tmp.SPQKCv
+ umask 022
+ cd /root/rpmbuild/BUILD
+ rm -rf libvirt-snmp-0.0.3
+ exit 0
# echo $?
0 #


libvirt-snmp rpm package will be created under ~/rpmbuild/RPMS/<arch>/ directory.
# ls ~/rpmbuild/RPMS/x86_64/
libvirt-snmp-0.0.3-1.el6.root1358398204.x86_64.rpm


install libvirt-snmp via yum
# yum --nogpgcheck localinstall ~/rpmbuild/RPMS/x86_64/libvirt-snmp-0.0.3-1.el6.root1358398204.x86_64.rpm –y
<snip>
Running Transaction
 Installing : libvirt-snmp-0.0.3-1.el6.root1358398204.x86_64               1/1
 Verifying  : libvirt-snmp-0.0.3-1.el6.root1358398204.x86_64               1/1

Installed:
 libvirt-snmp.x86_64 0:0.0.3-1.el6.root1358398204

Complete!


check options
# /usr/bin/libvirtMib_subagent --help
/usr/bin/libvirtMib_subagent: invalid option -- '-'
unknown option ?
usage: libvirtGuestTable [-D<tokens>] [-f] [-L] [-M] [-H] [LISTENING ADDRESSES]
       -f      Do not fork() from the calling shell.
       -DTOKEN[,TOKEN,...]
               Turn on debugging output for the given TOKEN(s).
               Without any tokens specified, it defaults to printing
               all the tokens (which is equivalent to the keyword 'ALL').
               You might want to try ALL for extremely verbose output.
               Note: You can't put a space between the -D and the TOKENs.
       -H      Display a list of configuration file directives
               understood by the agent and then exit.
       -M      Run as a normal SNMP Agent instead of an AgentX sub-agent.
       -x ADDRESS      connect to master agent at ADDRESS (default /var/agentx/master).
       -L      Do not open a log file; print all messages to stderr.


display configuration file directives to stderr.
# /usr/bin/libvirtMib_subagent -H -L
No log handling enabled - turning on stderr logging
Warning: no access control information configured.
 It's unlikely this agent can serve any useful purpose in this state.
 Run "snmpconf -g basic_setup" to help you configure the libvirtGuestTable.conf file for this agent.
Configuration directives understood:
 In libvirtGuestTable.conf and libvirtGuestTable.local.conf:
   authtrapenable           1 | 2              (1 = enable, 2 = disable)
   trapsink                 host [community] [port]
   trap2sink                host [community] [port]
   informsink               host [community] [port]
   trapsess                 [snmpcmdargs] host
   trapcommunity            community-string
   v1trapaddress            string
   agentuser                userid
<snip>


a MIB file for libvirt-snmp
# head -5 /usr/share/snmp/mibs/LIBVIRT-MIB.txt
LIBVIRT-MIB DEFINITIONS ::= BEGIN

--
-- libvirt.org MIB definition
--


[ SNMP configuration ]

- snmp get and set configuration
# cd /etc/snmp/
# cp snmpd.conf snmpd.conf.orig


edit snmpd.conf like this:
# egrep -v ^# /etc/snmp/snmpd.conf | grep -v ^$
com2sec notConfigUser  default       public
group   notConfigGroup v1           notConfigUser
group   notConfigGroup v2c           notConfigUser
view    systemview    included   .1
access  notConfigGroup ""      any       noauth    exact  systemview systemview none
access MyRWGroup ""      any       noauth    0      all    all    all
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
dontLogTCPWrappersConnects yes
master agentx
agentX Socket /var/agentx/master
trap2sink localhost public


start snmpd
# /etc/init.d/snmpd restart


run libvirtMib_subagent
# LIBVIRT_DEFAULT_URI="qemu:///system" libvirtMib_subagent -f -L
NET-SNMP version 5.5 AgentX subagent connected


try snmpbuldwalk to confirm you can get info about libvrit.
# snmpbulkwalk -v 2c -c public localhost -OX libvirtMIB -m all

LIBVIRT-MIB::libvirtGuestName[STRING: bc90f9d2-7366-2c60-891b-23224db5538] = STRING: "centos6-64-1"
LIBVIRT-MIB::libvirtGuestState[STRING: bc90f9d2-7366-2c60-891b-23224db5538] = INTEGER: running(1)
LIBVIRT-MIB::libvirtGuestCpuCount[STRING: bc90f9d2-7366-2c60-891b-23224db5538] = Gauge32: 1
LIBVIRT-MIB::libvirtGuestMemoryCurrent[STRING: bc90f9d2-7366-2c60-891b-23224db5538] = Gauge32: 1024
LIBVIRT-MIB::libvirtGuestMemoryLimit[STRING: bc90f9d2-7366-2c60-891b-23224db5538] = Gauge32: 1024
LIBVIRT-MIB::libvirtGuestCpuTime[STRING: bc90f9d2-7366-2c60-891b-23224db5538] = Counter64: 119410000000
LIBVIRT-MIB::libvirtGuestRowStatus[STRING: bc90f9d2-7366-2c60-891b-23224db5538] = INTEGER: active(1)


display snmp table
# snmptable -m ALL -v 2c -c public -Cb localhost libvirtGuestTable
SNMP table: LIBVIRT-MIB::libvirtGuestTable

          Name   State CpuCount MemoryCurrent MemoryLimit      CpuTime RowStatus
"centos6-64-1" running        1          1024        1024 120270000000    active


pause the VM “centos6-64-1” via snmpset.

before sending snmpset
# virsh list --all
Id    Name                           State
----------------------------------------------------
1     centos6-64-1                   running


pause the VM via snmp
# snmpset -m ALL -v 2c -c public localhost libvirtGuestState.\'bc90f9d2-7366-2c60-891b-23224db5538\' = paused
LIBVIRT-MIB::libvirtGuestState.'....sf,`...2$.U8' = INTEGER: paused(3)

# virsh list --all
Id    Name                           State
----------------------------------------------------
1     centos6-64-1                   paused


run
# snmpset -m ALL -v 2c -c public localhost libvirtGuestState.\'bc90f9d2-7366-2c60-891b-23224db5538\' = running
LIBVIRT-MIB::libvirtGuestState.'....sf,`...2$.U8' = INTEGER: running(1)

# virsh list --all
Id    Name                           State
----------------------------------------------------
1     centos6-64-1                   running


shutdown
# snmpset -m ALL -v 2c -c public localhost libvirtGuestState.\'bc90f9d2-7366-2c60-891b-23224db5538\' = shutdown

# virsh list --all
Id    Name                           State
----------------------------------------------------
-     centos6-64-1                   shut off


start the VM via snmp

at first check UUID
# snmpbulkwalk -v 2c -c public localhost -OX libvirtMIB -m all
LIBVIRT-MIB::libvirtGuestName[STRING: bc90f9d2-7366-2c60-891b-23224db5538] = STRING: "centos6-64-1"


start the VM
# virsh list –all
Id    Name                           State
----------------------------------------------------
-     centos6-64-1                   shut off

# snmpset -m ALL -v 2c -c public localhost libvirtGuestRowStat
us.\'bc90f9d2-7366-2c60-891b-23224db5538\' = createAndGo
LIBVIRT-MIB::libvirtGuestRowStatus.'....sf,`...2$.U8' = INTEGER: createAndGo(4)

# virsh list --all
Id    Name                           State
----------------------------------------------------
2     centos6-64-1                   running


- snmp trap configuration
# cat /etc/snmp/snmptrapd.conf
# Example configuration file for snmptrapd
#
# No traps are handled by default, you must edit this file!
#
# authCommunity   log,execute,net public
# traphandle SNMPv2-MIB::coldStart    /usr/bin/bin/my_great_script cold
authCommunity log test


run snmptrapd with foreground
# snmptrapd -f -Lo -c /etc/snmp/snmptrapd.conf --disableAuthorization=yes -m ALL
NET-SNMP version 5.5 AgentX subagent connected
NET-SNMP version 5.5


pause the VM
# snmpset -m ALL -v 2c -c public localhost libvirtGuestState.\'bc90f9d2-7366-2c60-891b-23224db5538\' = paused
LIBVIRT-MIB::libvirtGuestState.'....sf,`...2$.U8' = INTEGER: paused(3)

# snmptrapd -f -Lo -c /etc/snmp/snmptrapd.conf --disableAuthorization=yes -m ALL
NET-SNMP version 5.5 AgentX subagent connected
NET-SNMP version 5.5
2013-01-17 21::01:12 localhost.localdomain [UDP: [127.0.0.1]:43882->[127.0.0.1]]:
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (98514) 0:16:25.14     SNMPv2-MIB::snmpTrapOID.0 = OID: LIBVIRT-MIB::libvirtGuestNotif LIBVIRT-MIB::libvirtGuestName.0 = STRING: "centos6-64-1"        LIBVIRT-MIB::libvirtGuestUUID.1 = STRING: bc90f9d2-7366-2c60-891b-23224db5538   LIBVIRT-MIB::libvirtGuestState.2 = INTEGER: paused(3)   LIBVIRT-MIB::libvirtGuestRowStatus.3 = INTEGER: active(1)


shutdown the VM
# snmpset -m ALL -v 2c -c public localhost libvirtGuestState.\'bc90f9d2-7366-2c60-891b-23224db5538\' = shutdown
LIBVIRT-MIB::libvirtGuestState.'....sf,`...2$.U8' = INTEGER: shutdown(4)


trap message
2013-01-17 21::02:41 localhost.localdomain [UDP: [127.0.0.1]:43882->[127.0.0.1]]:
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (107358) 0:17:53.58    SNMPv2-MIB::snmpTrapOID.0 = OID: LIBVIRT-MIB::libvirtGuestNotif LIBVIRT-MIB::libvirtGuestName.0 = STRING: "centos6-64-1"        LIBVIRT-MIB::libvirtGuestUUID.1 = STRING: bc90f9d2-7366-2c60-891b-23224db5538   LIBVIRT-MIB::libvirtGuestState.2 = INTEGER: shutdown(4) LIBVIRT-MIB::libvirtGuestRowStatus.3 = INTEGER: notInService(2)
2013-01-17 21::02:41 localhost.localdomain [UDP: [127.0.0.1]:43882->[127.0.0.1]]:
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (107414) 0:17:54.14    SNMPv2-MIB::snmpTrapOID.0 = OID: LIBVIRT-MIB::libvirtGuestNotif LIBVIRT-MIB::libvirtGuestName.0 = STRING: "centos6-64-1"        LIBVIRT-MIB::libvirtGuestUUID.1 = STRING: bc90f9d2-7366-2c60-891b-23224db5538   LIBVIRT-MIB::libvirtGuestState.2 = INTEGER: shutoff(5)  LIBVIRT-MIB::libvirtGuestRowStatus.3 = INTEGER: notInService(2)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.