You are on page 1of 18

Conclusion

September 31, 2011


Zabcon
Introduction API Zabcon
Copyright 2011 Andrew Nelson, nelsonab@red-tuxnet
The Zabbix Console
The Zabbix API
and

Conclusion
September 31, 2011
Introduction
API & Zabcon
!our presenter
Andrew Nelson

"#C$, %abbix Certi&ied Spe'ialist

A'ti(e in the %abbix 'ommunity &or


approximately ) years

Nelsonab in the %abbix &orums

Creator o& %ab'on, the %abbix


'onsole
http*++tra'red-tuxnet

"ed #at Consultant


API Zabcon
Copyright 2011 Andrew Nelson, nelsonab@red-tuxnet

Conclusion
September 31, 2011
,a'-ground . /ntrodu'tion . $xample

/ntrodu'ed in %abbix 100

,ased on 1S2N-"3C ( 20 o(er #443

Not "$S4&ul

3ro(ides a somewhat raw inter&a'e to the internal data stru'tures

A3/ 'alls are made to the 5rontend, not the %abbix ser(er pro'ess

A3/ 'alls mimi' 5rontend a'ti(ities


Introduction API Zabcon
API & Zabcon
Copyright 2011 Andrew Nelson, nelsonab@red-tuxnet

Conclusion
September 31, 2011
Sounds interesting what do / need to -now6

7"8 used to a''ess the api*


9Ser(er 7"8:+api;<sonrp'php
$xample*
http*++myser(erexample'om+=abbix+api;<sonrp'php

A (alid %abbix user is re>uired &or all A3/ 'alls

2&ten re&erred to as the ?A3/ 7ser@

Aust be a member o& a 7ser group whi'h has the A3/ A''ess permission
enabled

A3/ 7sers are %abbix users with the ability to per&orm A3/ 'alls

4he latest do'umentation is online*


http*++www=abbix'om+do'umentation+10+api

4he &orum is a great resour'e


Introduction API Zabcon
,a'-ground . /ntrodu'tion . $xample
API & Zabcon
Copyright 2011 Andrew Nelson, nelsonab@red-tuxnet

Conclusion
September 31, 2011
Ay A3/ 7ser is 'on&igured, now what6

7se o& a %abbix A3/ library 'an ma-e things easier

Not re>uired, the bra(e use Curl and Bget

A3/ 'alls are di(ided into namespa'es

Namespa'e'all

userget, hostget et'

$(ery A3/ &un'tion re>uires a (alid session /C

$x'ept userlogin, whi'h is used to generate the session /C

,asi' A3/ Call+8ayout*


Introduction API Zabcon
,a'-ground . /ntrodu'tion . $xample
API & Zabcon
Copyright 2011 Andrew Nelson, nelsonab@red-tuxnet
{
"jsonrpc":"2.0",
"method":Function,
"params":{ Name:Value },
"auth":Session!,
"id":"ncrementin# Num$er%
}

2rder is not important, 'ontent is



Conclusion
September 31, 2011
Show me the dataD E8oginF
4he next &ew slides will show the steps needed to show all o& the hosts on a
system
Introduction API Zabcon
,a'-ground . /ntrodu'tion . $xample
API & Zabcon
Copyright 2011 Andrew Nelson, nelsonab@red-tuxnet
4he login*
{
"auth":null,"method":"user.lo#in",
"id":0,"jsonrpc":"2.0",
"params":{"pass&ord":"apitest","user":"apitest"}
}
{
"jsonrpc":"2.0",
"result":"e'((()'0c*(+')c,*d(0*(-c-($a)0,c",
"id":0
}
"esult*

Conclusion
September 31, 2011
Show me the dataD EhostgetF
Introduction API Zabcon
,a'-ground . /ntrodu'tion . $xample
API & Zabcon
Copyright 2011 Andrew Nelson, nelsonab@red-tuxnet
4he 'all*
{
"auth":"e'((()'0c*(+')c,*d(0*(-c-($a)0,c",
"method":"host.#et","id":-,
"params":{},"jsonrpc":"2.0"
}
{
"jsonrpc":"2.0",
"result":
.{"hostid":"(00,/"},{"hostid":"(00+,"},
{"hostid":"(00+/"}0,
"id":-
}
"esult*

Conclusion
September 31, 2011
Bait, is that all / get &rom hostget6
Introduction API Zabcon
,a'-ground . /ntrodu'tion . $xample
API & Zabcon
Copyright 2011 Andrew Nelson, nelsonab@red-tuxnet
8etGs try again with the parameter ?extend output@
{
"auth":"e'((()'0c*(+')c,*d(0*(-c-($a)0,c","id":,,
"method":"host.#et", "params":{"output":"e1tend"},
"jsonrpc":"2.0"
}

Conclusion
September 31, 2011
#oly data ,atman, thatGs a lotD
Introduction API Zabcon
,a'-ground . /ntrodu'tion . $xample
API & Zabcon
Copyright 2011 Andrew Nelson, nelsonab@red-tuxnet
{"jsonrpc":"2.0",
"result":
.{"maintenances":.{"maintenanceid":"0"}0,
"hostid":"(00,/","pro123hostid":"0","host":"test","dns":"",
"useip":"(","ip":"(2/.0.0.(","port":"(0040","status":"0",
"disa$le3until":"0","error":"","a5aila$le":"0",
"errors3'rom":"0","lastaccess":"0","in$2tes":"0","out$2tes":"0",
"useipmi":"0","ipmi3port":"+2-","ipmi3autht2pe":"6(",
"ipmi3pri5ile#e":"2","ipmi3username":"","ipmi3pass&ord":"",
"ipmi3disa$le3until":"0","ipmi3a5aila$le":"0",
"snmp3disa$le3until":"0","snmp3a5aila$le":"0",
"maintenanceid":"0","maintenance3status":"0",
"maintenance3t2pe":"0","maintenance3'rom":"0","ipmi3ip":"",
"ipmi3errors3'rom":"0","snmp3errors3'rom":"0","ipmi3error":"",
"snmp3error":""},
{ 7runcated !ata 'or 8ost 2"}, {7runcated !ata 'or 8ost-}0,
"id":,}
"esult*

Conclusion
September 31, 2011
/s there an easier way6

%ab'on is intended to be the ?%abbix Console@

Started in late 200H

8atest (ersion 00332 Ereleased todayDF

Bebsite* http*++tra'red-tuxnet

Britten in "uby

"e>uires at least 10I

No ma<or issues with 1Hx, please report them when you &ind them

Can a''ept 'ommands &rom standard input

2ne person used %ab'on inside a s'ript to import data into %abbix, using this
approa'h they were able to import about 1,000 hots in a matter o& minutes

7sers 'an 'reate their own 'ustom %ab'on 'ommands

$asiest way to install is &rom "ubygems


J gem install =ab'on

/nstallation and update o& dependen'ies is managed by "ubygems

Some dependen'ies may re>uire a 'ompiler and the "uby de(elopment


libraries
Introduction API Zabcon
API & Zabcon
Copyright 2011 Andrew Nelson, nelsonab@red-tuxnet
/ntrodu'tion . $xample . Simpli&ying things . Aore examples . Ad(an'ed

Conclusion
September 31, 2011
8etGs see that get host example with %ab'on
9 :a$con.r$
;na$le to 'ind a de'ault con'i#uration 'ile
i-)+6linu1
<elcome to =a$con. >uild Num$er: -2+
;se the command ?help? to #et help on commands
6% lo#in http:@@(*2.(+).(++.(0 apitest apitest
http:@@(*2.(+).(++.(0 connected
AB Version: (.-
C% #et host
8ost result set
C66666666C6666666666C66666C66666666666C
D hostid D host D dns D ip D
C66666666C6666666666C66666C66666666666C
D (00,/ D test D D (2/.0.0.( D
D (00+, D Eua 2 D D 0.0.0.0 D
D (00+/ D ne& test D D (2/.0.0.( D
C66666666C6666666666C66666C66666666666C
- ro&s total
C%
Introduction API Zabcon
API & Zabcon
Copyright 2011 Andrew Nelson, nelsonab@red-tuxnet
/ntrodu'tion . $xample . Simpli&ying things . Aore examples . Ad(an'ed

Conclusion
September 31, 2011
4hatGs ni'e do / really need to log in e(ery time6
ser5erFhttp:@@(*2.(+).(++.(0@
usernameFapitest
pass&ordFapitest
Gde$u#F0
Gtruncate3len#thF4000
Gcustom3commandsFsample3custom3commands
Introduction API Zabcon
API & Zabcon
Copyright 2011 Andrew Nelson, nelsonab@red-tuxnet

%ab'on 'an load host and user in&ormation &rom a 'on&iguration &ile

Ce&ault beha(ior is to load the 'on&ig &ile upon startup

+=ab'on'on& and K+=ab'on'on& are sear'hed in that order

Sample 'on&ig &ile* =ab'on'on&de&ault 'an be &ound in your systemGs


"ubygems dire'tory
9 #em &hich :a$con
@usr@li$@ru$2@#ems@(.)@#ems@:a$con60.0.--2@.@:a$con.r$

7sing the abo(e in&ormation the sample 'on&ig &ile would be &ound at *
@usr@li$@ru$2@#ems@(.)@#ems@:a$con60.0.--2@:a$con.con'.de'ault

$xample*
/ntrodu'tion . $xample . Simpli&ying things . Aore examples . Ad(an'ed

Conclusion
September 31, 2011
8etGs try that again, with more in&ormation*
9 :a$con.r$
i-)+6linu1
Found 5alid lo#in credentials, attemptin# lo#in
http:@@(*2.(+).(++.(0 connected
AB Version: (.-
<elcome to =a$con. >uild Num$er: -2+
;se the command ?help? to #et help on commands
C% #et host sho&Fhostid,host,dns,ip,a5aila$le,status
8ost result set
C66666666C6666666666C66666C66666666666C66666666666C66666666C
D hostid D host D dns D ip D a5aila$le D status D
C66666666C6666666666C66666C66666666666C66666666666C66666666C
D (00,/ D test D D (2/.0.0.( D 0 D 0 D
D (00+, D Eua 2 D D 0.0.0.0 D 0 D 0 D
D (00+/ D ne& test D D (2/.0.0.( D 0 D 0 D
C66666666C6666666666C66666C66666666666C66666666666C66666666C
- ro&s total
C%
Introduction API Zabcon
API & Zabcon
Copyright 2011 Andrew Nelson, nelsonab@red-tuxnet
/ntrodu'tion . $xample . Simpli&ying things . Aore examples . Ad(an'ed

Conclusion
September 31, 2011
2- thatGs 'ool but what i& / want to disable a host &rom a s'ript6
9 echo "get host show=hostid,host,dns,ip,status" !abcon"rb
hostid,host,dns,ip,status
(00,/,test,,(2/.0.0.(,0
(00+,,Eua 2,,0.0.0.0,0
(00+/,ne& test,,(2/.0.0.(,0
9 echo "update host hostid=#$$%& status=#" !abcon"rb
9 echo "get host show=hostid,host,dns,ip,status" !abcon"rb
hostid,host,dns,ip,status
(00,/,test,,(2/.0.0.(,(
(00+,,Eua 2,,0.0.0.0,0
(00+/,ne& test,,(2/.0.0.(,0
Introduction API Zabcon
API & Zabcon
Copyright 2011 Andrew Nelson, nelsonab@red-tuxnet
/ntrodu'tion . $xample . Simpli&ying things . Aore examples . Ad(an'ed

Conclusion
September 31, 2011
A''essing the A3/ dire'tly
C% ra& api histor2.#et itemidsF.22(+-0 time3'romF(-(/-+/2-2
time3toF(-(/-+/2+2 outputFe1tend
Ha&3api result set
C666666666666C66666666C666666666666C
D clocI D itemid D 5alue D
C666666666666C66666666C666666666666C
D (-(/-+/2)- D 22(+- D (-(/-+/2)- D
D (-(/-+/-,- D 22(+- D (-(/-+/-,- D
...
D (-(/-+/*,- D 22(+- D (-(/-+/*,- D
D (-(/-+)00- D 22(+- D (-(/-+)00- D
C666666666666C66666666C666666666666C
(- ro&s total
Introduction API Zabcon
API & Zabcon
Copyright 2011 Andrew Nelson, nelsonab@red-tuxnet

"ight now, %ab'on does not ha(e a 'ommand &or e(ery possible A3/ 'all

?raw api@ allows dire't a''ess to the api


/ntrodu'tion . $xample . Simpli&ying things . Aore examples . Ad(an'ed

Conclusion
September 31, 2011
Custom 'ommands
=a$conJommand.add3command "custom" do
set3method do DparamsD
ser5er.connection.ra&3apiK"user.#et",{}L
end
set3help3ta# :none
set3'la# :print3output
end
Introduction API Zabcon
API & Zabcon
Copyright 2011 Andrew Nelson, nelsonab@red-tuxnet

$nd users 'an 'reate their own %ab'on 'ommands to suit their own uni>ue needs

4he 'ommand ?help 'ommands@ will be updated with the new 'ommands

%ab'on'on& &ile determines the lo'ation o& the 'ustom 'ommands &ile

Custom 'ommands &ile is only parsed on %ab'on startup


C% custom
result set
C66666666C
D userid D
C66666666C
D ( D
D 2 D
C66666666C
2 ro&s total
/ntrodu'tion . $xample . Simpli&ying things . Aore examples . Ad(an'ed

Conclusion
September 31, 2011
Custom 'ommands
=a$conJommand.add3command "custom" do
set3method do DparamsD
ser5er.connection.ra&3apiK"user.#et",{}L
end
set3help3ta# :none
set3'la# :print3output
end
Introduction API Zabcon
API & Zabcon
Copyright 2011 Andrew Nelson, nelsonab@red-tuxnet

$nd users 'an 'reate their own %ab'on 'ommands to suit their own uni>ue needs

4he 'ommand ?help 'ommands@ will be updated with the new 'ommands

%ab'on'on& &ile determines the lo'ation o& the 'ustom 'ommands &ile

Custom 'ommands &ile is only parsed on %ab'on startup


C% custom
result set
C66666666C
D userid D
C66666666C
D ( D
D 2 D
C66666666C
2 ro&s total
/ntrodu'tion . $xample . Simpli&ying things . Aore examples . Ad(an'ed

September 31, 2011
4ime &or me to stop tal-ing
Introduction API Zabcon
"e'ap
API & Zabcon
Copyright 2011 Andrew Nelson, nelsonab@red-tuxnet

A3/ is 1S2N-"3C based

Allows &or a nearly 'omplete inter&a'e &or modi&ying %abbix

A3/ 'alls are made to the Beb &ronend

%ab'on allows you to easilly 'all the %abbix A3/ &orm the 'ommand line or s'ripts

#elp &rom more de(elopers and testers is always appre'iated Ehint hintF
Bebsite*
http*++tra'red-tuxnet
$mail*
nelsonab@red-tuxnet
anelson@redhat'om
Conclusion

You might also like