Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- # [2016] Infobl0x, Inc.
- # All Rights Reserved.
- # NOTICE: All information contained herein is, and remains the property of Infoblox, Inc. and its suppliers, if any.
- # The intellectual and technical concepts contained herein are proprietary to Infoblox, Inc and its suppliers and may
- # be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret or copyright law.
- # Dissemination of this information or reproduction of this material is strictly forbidden unless prior written
- # permission is obtained from Infoblox, Inc.
- use strict;
- use warnings;
- use Data::Dumper;
- $Data::Dumper::Indent = 3;
- use Net::Ping;
- use Infoblox;
- my $login = (getpwuid $>);
- if ($login ne 'root') {
- print "This script must be run as root, run with the 'sudo' command\n";
- exit(66);
- }
- my $ibhost = "10.100.0.100";
- my $ibuser = "api";
- my $ibpass = "Infobl0x";
- # Setting up print styles
- my $error = "[\e[1;31m><\e[0m]";
- my $good = "[\e[0;32mOK\e[0m]";
- my $info = "[\e[1;37m--\e[0m]";
- my $warn = "[\e[1;33m!!\e[0m]";
- my $empty = " ";
- my $dbug = "[\e[0;35m??\e[0m]";
- # Functions that handle the print styles
- sub errorprint($) { print $error . " " . $_[0]; }
- sub goodprint($) { print $good . " " . $_[0]; }
- sub infoprint($) { print $info . " " . $_[0]; }
- sub warnprint($) { print $warn . " " . $_[0]; }
- sub emptyprint($) { print $empty . " " . $_[0]; }
- sub debugprint($) { if ((defined $ARGV[0]) && ($ARGV[0] eq "--debug")) { print $dbug . " " . $_[0];}}
- sub trim($) {
- my $string = $_[0];
- $string =~ s/^\s+//;
- $string =~ s/\s+$//;
- return $string;
- }
- my $p = Net::Ping->new('icmp');
- $p->bind("10.100.0.10");
- infoprint "Testing Network Connectivity\n";
- if ($p->ping($ibhost)) {
- goodprint "Ping check to " . $ibhost . " was successful\n";
- my $SESSION = Infoblox::Session->new(
- 'master' => $ibhost,
- 'username' => $ibuser,
- 'password' => $ibpass,
- );
- print "\n";
- infoprint "Testing API Connectivity\n";
- if ($SESSION->status_code()) {
- my $result = $SESSION->status_code();
- my $response = $SESSION->status_detail();
- errorprint "API connection failed (" . $ibuser . '@' . $ibhost . ")\n";
- errorprint $response . " (" . $result . ")\n";
- } else {
- goodprint "API connection established (" . $ibuser . '@' . $ibhost . ")\n";
- goodprint "Server Version: " . $SESSION->server_version() . "\n";
- }
- } else {
- errorprint "Ping check to " . $ibhost . " failed\n";
- exit(99);
- }
- $p->close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement