Advertisement
Guest User

Infobl0x - checkAPIUser.pl

a guest
Oct 27th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.47 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. # [2016] Infobl0x, Inc.
  4. # All Rights Reserved.
  5. # NOTICE: All information contained herein is, and remains the property of Infoblox, Inc. and its suppliers, if any.
  6. # The intellectual and technical concepts contained herein are proprietary to Infoblox, Inc and its suppliers and may
  7. # be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret or copyright law.
  8. # Dissemination of this information or reproduction of this material is strictly forbidden unless prior written
  9. # permission is obtained from Infoblox, Inc.
  10.  
  11. use strict;
  12. use warnings;
  13. use Data::Dumper;
  14. $Data::Dumper::Indent = 3;
  15. use Net::Ping;
  16. use Infoblox;
  17.  
  18. my $login = (getpwuid $>);
  19. if ($login ne 'root') {
  20.     print "This script must be run as root, run with the 'sudo' command\n";
  21.     exit(66);
  22. }
  23.  
  24. my $ibhost = "10.100.0.100";
  25. my $ibuser = "api";
  26. my $ibpass = "Infobl0x";
  27.  
  28. # Setting up print styles
  29. my $error = "[\e[1;31m><\e[0m]";
  30. my $good = "[\e[0;32mOK\e[0m]";
  31. my $info = "[\e[1;37m--\e[0m]";
  32. my $warn = "[\e[1;33m!!\e[0m]";
  33. my $empty = "    ";
  34. my $dbug = "[\e[0;35m??\e[0m]";
  35.  
  36. # Functions that handle the print styles
  37. sub errorprint($) { print $error . " " . $_[0]; }
  38. sub goodprint($) { print $good . " " . $_[0]; }
  39. sub infoprint($) { print $info . " " . $_[0]; }
  40. sub warnprint($) { print $warn . " " . $_[0]; }
  41. sub emptyprint($) { print $empty . " " . $_[0]; }
  42. sub debugprint($) { if ((defined $ARGV[0]) && ($ARGV[0] eq "--debug")) { print $dbug . " " . $_[0];}}
  43. sub trim($) {
  44.     my $string = $_[0];
  45.     $string =~ s/^\s+//;
  46.     $string =~ s/\s+$//;
  47.     return $string;
  48. }
  49.  
  50. my $p = Net::Ping->new('icmp');
  51. $p->bind("10.100.0.10");
  52.  
  53. infoprint "Testing Network Connectivity\n";
  54.  
  55. if ($p->ping($ibhost)) {
  56.  
  57.     goodprint "Ping check to " . $ibhost . " was successful\n";
  58.  
  59.     my $SESSION = Infoblox::Session->new(
  60.         'master'   => $ibhost,
  61.         'username' => $ibuser,
  62.         'password' => $ibpass,
  63.     );
  64.  
  65.     print "\n";
  66.     infoprint "Testing API Connectivity\n";
  67.  
  68.     if ($SESSION->status_code()) {
  69.  
  70.         my $result = $SESSION->status_code();
  71.         my $response = $SESSION->status_detail();
  72.  
  73.         errorprint "API connection failed (" . $ibuser . '@' . $ibhost . ")\n";
  74.         errorprint $response . " (" . $result . ")\n";
  75.  
  76.     } else {
  77.  
  78.         goodprint "API connection established (" . $ibuser . '@' . $ibhost . ")\n";
  79.         goodprint "Server Version: " . $SESSION->server_version() . "\n";
  80.  
  81.     }
  82.  
  83. } else {
  84.  
  85.     errorprint "Ping check to " . $ibhost . " failed\n";
  86.     exit(99);
  87.  
  88. }
  89. $p->close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement