NAME
MikroTik::API - Client to MikroTik RouterOS API
VERSION
Version 0.01
SYNOPSIS
use MikroTik::API;
my $api = MikroTik::API->new({
host => 'mikrotik.example.org',
username => 'whoami',
password => 'SECRET',
use_ssl => 1,
});
my ( $ret_get_identity, @aoh_identity ) = $api->query( '/system/identity/print', {}, {} );
print "Name of router: $aoh_identity[0]->{name}\n";
$api->logout();
DESCRIPTION
PUBLIC METHODS
new( \%config )
my $api = MikroTik::API->new({
host => 'mikrotik.example.org',
username => 'whoami',
password => 'SECRET',
use_ssl => 1, # optional (0 for non ssl / 1 for ssl)
port => 8729, # optonal (needed if you use another port then 8728 for non-ssl or 8729 for ssl)
debug => 0, # optional (set beween 0 (none) and 5 (most) for debug messages)
});
$api->connect()
Connect happens on construction if you provide host address
my $api = MikroTik::API->new();
$api->set_host('mikrotik.example.org');
$api->set_port(1234);
$api->set_use_ssl(1);
$api->connect();
$api->login()
Connect happens on construction if you provide host address, username and password
my $api = MikroTik::API->new({ host => 'mikrotik.example.org' });
$api->set_username('whoami');
$api->set_password('SECRET');
$api->login();
$api->logout()
$api->logout();
$api->cmd( $command, \%attributes )
my $returnvalue = $api->cmd( '/system/identity/set', { 'name' => 'MyNewMikroTik' } );
print "Name set\n" if ($returnvalue < 2);
$api->query( $command, \%attributes, \%conditions )
my ( $ret_interface_print, @interfaces ) = $api->query('/interface/print', { '.proplist' => '.id,name' }, { type => 'ether' } );
foreach my $interface ( @interfaces ) {
print "$interface->{name}\n";
}
$api->get_by_key( $command, $keycolumn )
my %interface = $api->get_by_key('/interface/ethernet/print', 'name' );
print "$interface{'ether1'}->{running}\n";
ACCESSORS
$api->get_host(), $api->set_host( $hostname )
$api->get_port(), $api->set_port( $portnumber )
$api->get_username(), $api->set_username( $username )
$api->get_password(), $api->set_password( $password )
$api->get_use_ssl(), $api->set_use_ssl( $zero_or_one )
$api->get_socket(), $api->set_socket( $io_socket )
my $socket = IO::Socket::INET->new();
$api->set_socket( $socket );
$api->get_debug(), $api->set_debug( $int )
$api->set_debug(0); # no debug
$api->set_debug(5); # verbose debug to STDOUT
SEMI-PUBLIC METHODS
can be useful for advanced users, but too complex for daily use
$api->talk( \@sentence )
$api->raw_talk( \@sentence )
ABOUT
Contributors
Object-Orientated Rebuild of prior contributions, based on:
inital release from cheesegrits in MikroTik forum: http://forum.mikrotik.com/viewtopic.php?p=108530#p108530
added timeoutparameter and fixes by elcamlost: https://github.com/elcamlost/mikrotik-perl-api/commit/10e5da1fd0ccb4a249ed3047c1d22c97251f666e
SSL support by akschu: https://github.com/akschu/MikroTikPerl/commit/9b689a7d7511a1639ffa2118c8e549b5cec1290d
Design decisions
Use of Moose for OO
higher compilation time of Moose based lib negligible because of slow I/O operations
Moose is more common than Moo or similar
AUTHOR
Martin Gojowsky, <martin at gojowsky.de>
BUGS
Please report any bugs or feature requests to bug-mikrotik-api at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MikroTik-API. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc MikroTik::API
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
Copyright 2015 Martin Gojowsky.
This program is distributed under the MIT (X11) License: http://www.opensource.org/licenses/mit-license.php
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.