lost and found ( for me ? )

Showing posts with label libvirt-snmp. Show all posts
Showing posts with label libvirt-snmp. Show all posts

how to install libvirt-snmp on Ubuntu 12.10


# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 12.10
Release:        12.10
Codename:       quantal

# uname -ri
3.5.0-22-generic x86_64

# libvirtd --version
libvirtd (libvirt) 0.9.13

# kvm --version
QEMU emulator version 1.2.0 (qemu-kvm-1.2.0+noroms-0ubuntu2.12.10.2, Debian), Copyright (c) 2003-2008 Fabrice Bellard

[ install libvirt-snmp ]

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

# cd libvirt-snmp

error
# ./autobuild.sh
<snip>
checking for LIBVIRT... no
configure: error: Package requirements (libvirt >= 0.8.0) were not met:

No package 'libvirt' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables LIBVIRT_CFLAGS
and LIBVIRT_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

no libvirt traces..
# pkg-config --list-all | grep libvirt
#

it seems that I need to install libvirt library
# apt-get install libvirt-dev

# pkg-config --list-all | grep libvirt
libvirt                        libvirt - libvirt library

again .. error
# ./autobuild.sh
<snip>
config.status: creating config.h
config.status: executing depfiles commands

Now type 'make' to compile libvirt-snmp.

make
make  all-recursive
make[1]: Entering directory `/root/libvirt-snmp/build'
Making all in src/
make[2]: Entering directory `/root/libvirt-snmp/build/src'
gcc -DHAVE_CONFIG_H -I. -I../../src -I..     -DNETSNMP_ENABLE_IPV6 -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Ulinux -Dlinux=linux -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fstack-protector -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/lib/perl/5.14/CORE -D_FORTIFY_SOURCE=2 -I/usr/include     -g -O2 -MT libvirtMib_subagent-libvirtGuestTable_data_get.o -MD -MP -MF .deps/libvirtMib_subagent-libvirtGuestTable_data_get.Tpo -c -o libvirtMib_subagent-libvirtGuestTable_data_get.o `test -f 'libvirtGuestTable_data_get.c' || echo '../../src/'`libvirtGuestTable_data_get.c
../../src/libvirtGuestTable_data_get.c:24:38: fatal error: net-snmp/net-snmp-config.h: No such file or directory
compilation terminated.
make[2]: *** [libvirtMib_subagent-libvirtGuestTable_data_get.o] Error 1
make[2]: Leaving directory `/root/libvirt-snmp/build/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/libvirt-snmp/build'
make: *** [all] Error 2


I forgot installing snmp related packages which are required to build libvirt-snmp.
install snmp packages which are required to build libvirt-snmp
# apt-get install snmp snmpd libsnmp-dev libsnmp-perl –y

# ./autobuild.sh


libvirt-snmp.tgz will be created under “libvirt-snmp/build” directory.
# ls ~/libvirt-snmp/build/*.tar.gz
/root/libvirt-snmp/build/libvirt-snmp-0.0.3.tar.gz


build
# cp libvirt-snmp/build/libvirt-snmp-0.0.3.tar.gz /root/
# tar xzvf libvirt-snmp-0.0.3.tar.gz
# cd libvirt-snmp-0.0.3/
# ./configure
# make
# make install

# which libvirtMib_subagent
/usr/local/bin/libvirtMib_subagent


[ snmp configuration ]
# cat /etc/snmp/snmpd.conf
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


restart snmpd
# /etc/init.d/snmpd restart
* Restarting network management services:


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


send snmp packets
nnn , can’t find MIBs..
# snmpbulkwalk -c public -v2c localhost . -m ALL | head -5
MIB search path: /root/.snmp/mibs:/usr/share/mibs/site:/usr/share/snmp/mibs:/usr/share/mibs/iana:/usr/share/mibs/ietf:/usr/share/mibs/netsnmp
Cannot find module (SNMPv2-SMI): At line 10 in /usr/share/mibs/netsnmp/LIBVIRT-MIB.txt
Cannot find module (SNMPv2-TC): At line 14 in /usr/share/mibs/netsnmp/LIBVIRT-MIB.txt
Did not find 'enterprises' in module #-1 (/usr/share/mibs/netsnmp/LIBVIRT-MIB.txt)
<snip>

check MIB path
# net-snmp-config --default-mibdirs
/root/.snmp/mibs:/usr/share/mibs/site:/usr/share/snmp/mibs:/usr/share/mibs/iana:/usr/share/mibs/ietf:/usr/share/mibs/netsnmp

download MIBs
# apt-get install -y snmp-mibs-downloader

some errors were displayed , however I was able to translate SNMP GET replies with MIBs.
# snmpbulkwalk -v 2c -c public localhost -OX libvirtMIB -m all
Undefined OBJECT-GROUP (diffServMIBMultiFieldClfrGroup): At line 2195 in /usr/share/mibs/ietf/IPSEC-SPD-MIB
Undefined OBJECT-GROUP (diffServMultiFieldClfrNextFree): At line 2157 in /usr/share/mibs/ietf/IPSEC-SPD-MIB
Undefined OBJECT-GROUP (diffServMIBMultiFieldClfrGroup): At line 2062 in /usr/share/mibs/ietf/IPSEC-SPD-MIB
Bad operator (INTEGER): At line 73 in /usr/share/mibs/ietf/SNMPv2-PDU
Unlinked OID in IPATM-IPMC-MIB: marsMIB ::= { mib-2 57 }
Undefined identifier: mib-2 near line 18 of /usr/share/mibs/ietf/IPATM-IPMC-MIB
Expected "::=" (RFC5644): At line 493 in /usr/share/mibs/iana/IANA-IPPM-METRICS-REGISTRY-MIB
Expected "{" (EOF): At line 651 in /usr/share/mibs/iana/IANA-IPPM-METRICS-REGISTRY-MIB
Bad object identifier: At line 651 in /usr/share/mibs/iana/IANA-IPPM-METRICS-REGISTRY-MIB
Bad parse of OBJECT-IDENTITY: At line 651 in /usr/share/mibs/iana/IANA-IPPM-METRICS-REGISTRY-MIB
LIBVIRT-MIB::libvirtGuestName[STRING: 4866b0fd-b782-45ad-3b73-c480960ea08f] = STRING: "ubuntu12-04-vm1"
LIBVIRT-MIB::libvirtGuestName[STRING: 486887f5-2501-75ec-33a7-9985911fe0a1] = STRING: "ubuntu12-04-vm2"
<snip>

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)