Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use strict;
- use warnings;
- use JSON;
- use List::Util;
- use Zabbix::Tiny;
- use Data::Dumper;
- use zabbixhost;
- my @url = ("http://zabbix/api_jsonrpc.php", 'http://192.168.66.114/api_jsonrpc.php');
- my $oldZabbix;
- my $newZabbix;
- my @hostAttributes = zabbixhost->giveAttributes;
- my $tiniesJSON;
- my $hostilon;
- my $username = "xx";
- my $password = "xx";
- my %functions = (
- CopyHost => \&getHostAttributesFromServer,
- HostToServer => \&createHostsOnServer,
- Login => \&loginInput,
- Exit => sub {return 0},
- );
- &loginInput;
- while(&menue){};
- sub menue{
- print "Choose wisely\n\n";
- print "$_\n" for keys %functions;
- my $task = <STDIN>;
- chomp($task);
- if(exists $functions{$task}){
- print "\n\n";
- $functions{$task}->();
- }else{
- print "Fehlerhafte eingabe try again\n\n";
- }
- return 1;
- }
- sub createHostsOnServer{
- getHostAttributesFromServer();
- my @host;
- my @arguments;
- for ( @{$tiniesJSON} ) {
- #print Dumper($_)."\n";
- push @host,$_;
- }
- print Dumper(@arguments);
- $newZabbix->do(
- 'host.create',
- output => [@host]
- );
- }
- sub getHostAttributesFromServer{
- chomp (@hostAttributes);
- $tiniesJSON = $oldZabbix->do(
- 'host.get', # First argument is the Zabbix API method
- output => [@hostAttributes], # Remaining parameters to 'do' are the params for the oldZabbix method.
- monitored => 1,
- limit => 2
- );
- return 1;
- }
- sub loginInput{
- foreach my $server(@url){
- print "Login Process for $server\n";
- print "Username: ";
- chomp( $username=<STDIN>);
- print "Password: ";
- chomp( $password=<STDIN>);
- login($username,$password,$server);
- }
- }
- sub login{
- my $server;
- if(@_ == 3){
- $username=shift (@_);
- $password=shift (@_);
- $server=shift(@_);
- } else {
- chomp($username);
- chomp($password);
- }
- eval {
- if($server eq $url[0]){
- $oldZabbix = Zabbix::Tiny->new(
- server => $server,
- password => $password,
- user => $username
- );
- }else{
- $newZabbix = Zabbix::Tiny->new(
- server => $server,
- password => $password,
- user => $username
- );
- }
- if ($@) {
- print "\n\nLogin or URL are wrong, program is exiting now!\n\n";
- return 0;
- } else {
- print "\n\nLogin sucessfully performed on $server\n\n";
- return 1;
- }
- };
- }
- sub checkForDuplicates {
- }
- 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement