Advanced MikroTik Monitoring Via API
Advanced MikroTik Monitoring Via API
Advanced MikroTik Monitoring Via API
About
ME
Herry
Darmawan
Working
for
:
Spectrum
Indonesia
Posi*on
:
Technical
and
Opera*onal
Manager
Home
base
:
Surabaya,
Indonesia
Introducing
Nagios
Web
based
monitoring
system
Modular
Check
plugin
(in
perl
or
c++)
Lots
of
improvement
module
(front-end,
polling,
3rd
party
integra*on,
etc)
Database
backend
NDOMY
MySQL
Postgres
SQL
Plugin short-name
Centreon
-
command
The
actual
command
prompt
with
some
MACROs
Process
Processing
and
gathering
informa*on
from
device
Return
Value
Result
display
RRD
result
Service
status
return
Process
Is
the
real
process
All
process
(SNMP,
Telnet,
SSH,
API)
is
happening
in
this
part
Beware
to
check
the
structure
Case
Study
Scenario
192.168.2.1
MR4
192.168.4.1
OSPF
MR5
192.168.5.1
192.168.1.1
192.168.3.1 192.168.3.2
Monitoring
OSPF
What
parameter
do
we
need?
Router
IP
API
Port
(in
this
case,
we
use
the
default
port)
Username
and
Password
for
the
API
Interface
NAME
/
NUMBER
Threshold
Value
We will create a help menu which will be shown if there is uncompleted parameters given
Final
RESULT
my %ERRORS=('OK'=>0,! ! 'WARNING'=>1,! ! 'CRITICAL'=>2,! ! 'UNKNOWN'=>3,! ! 'DEPENDENT'=>4);!
if ($errmsg) {! !print $errmsg."\n";! } else {! !print "$status : "OSPF status for $intname ! ! ! ! !is $state for $adjacency \n";! }! exit $ERRORS{$status};!
Integrate to NAGIOS
$USER1$/check_ospf.pl m $HOSTADDRESS$ -u api p test i $ARG1$! IP Address of the HOST ARGUMENT1 could be dierent for each service /usr/lib/nagios/plugins
Attach it to HOST
Command short-name
TESTING
Drawbacks
API
connec*on
will
constantly
ini*ate
and
closed
each
*me
the
monitoring
tools
doing
polling
to
the
device
/
host
Not
as
fast
as
SNMP
(since
we
are
using
TCP
Socket
conn)
Improvement
Instead
of
just
checking
the
OSPF
status,
why
dont
we
check
the
trac
u*liza*on
as
well
and
give
alert
if
it
reach
some
threshold?
./check_ospf m <RA> -u <U> -p <P> -i ether1 w 10 c 100! Will show the OSPF Status, along with the u*liza*on of interface name ether1 with condi*on like this : IF the trac u*lized is more than 10kbps (-w 10) then this service status is considered WARNING IF the trac u*lized is more than 100kbps (-c 100) then this service status is considered CRITICAL IF the status of OSPF <> FULL, then considered CRITICAL GRAPH the TX and RX trac
TrafBic
Utilization
IF
the
trac
u*lized
is
more
than
10kbps
(-w
10)
then
this
service
status
is
considered
WARNING
IF
the
trac
u*lized
is
more
than
100kbps
(-c
100)
then
this
service
status
is
considered
CRITICAL
First
of
all,
we
will
take
the
external
value
for
the
WARNING
and
CRITICAL
threshold
WARNING
threshold
is
taken
by
parameter
w! CRITICAL
threshold
is
taken
by
parameter
-c!
TrafBic
Utilization
In
Terminal
we
write
it
like
this
!/interface monitor-traffic [ether1]!
In
API,
we
write
it
like
this
!/interface/monitor-traffic! !=once=! !=interface=[ether1]! !
TrafBic
Utilization
### TAKING the interface number from the parameter! my($intno) = $options{'i'}; ! ! ### Getting the interface name (the monitor-traffic use name)! $intattrs{'=.proplist'} = 'name';! $intattrs{'.id'} = $intno;! $intname = Mtik::get_value_by_id! ! !('/interface/getall', $intno, 'name', \%intattrs);! ! !! ### Getting the real traffic from monitor-traffic command ! !! $trafficattr{'=.proplist'} = ! ! ! !'rx-bits-per-second, tx-bits-per-second';! $trafficattr{'=once'} = '';! $trafficattr{'=interface'} = $intname;! my(%traffics) = Mtik::get_by_key! ! !(/interface/monitor-traffic, \%trafficattr);! $txbits = $traffics{$intno}{'tx-bits-per-second'};! $rxbits = $traffics{$intno}{'rx-bits-per-second'};!
TrafBic
Utilization
Now
we
compare
the
bits
received
with
the
actual
Threshold
if ($txbits > $warningbits || $rxbits > $warningbits) {! !$retmsg .= " but the traffic exceeded the threshold";! !$status = "WARNING";! } elsif ($txbits > $criticalbits || $rxbits > $criticalbits) {! !$retmsg .= " but the traffic exceeded the threshold";! !$status = "CRITICAL";! }! ! print "$status : $retmsg \n";! printf("Traffic Utilization : TX : %.2f ".$txprefix."bps/ ! ! RX : %.2f ".$rxprefix."bps\n! !,$txdispbits,$rxdispbits);! print "|traffic_in=".$txbits."Bits/s;! ! ! !$warningbits;$criticalbits ! ! traffic_out=".$rxbits."Bits/s;! ! ! !$warningbits;$criticalbits\n";! exit $ERRORS{$status};!
Visual Result
Whats
NEXT?
Basically
we
can
monitor
and
graph
anything
Graph
BGP
prexes
received
and
alert
when
the
BGP
DOWN
or
the
prexes
reach
some
low
threshold
Graph
the
number
of
Ac*ve
Hotspot
user,
Host
that
connected
to
a
Hotspot
server,
and
the
number
of
DHCP
Lease
that
has
been
established
Graph
the
number
of
sta*on
that
connect
to
an
Access
Point
Graph
TX/RX
Rate
and
CCQ
of
a
connec*on
and
send
alert
once
they
goes
below
certain
threshold
hup://project.spectrumindo.com hup://www.mikro*ktraining.co.id
FURTHER
QUESTION
[email protected]