Skip to content

Instantly share code, notes, and snippets.

@hogihung
Created March 31, 2016 20:28
Show Gist options
  • Save hogihung/dc0343e0bfaec0bedf996ca02d688fb1 to your computer and use it in GitHub Desktop.
Save hogihung/dc0343e0bfaec0bedf996ca02d688fb1 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
#
# John Hogarty
#
# Description: This is a test script to test components of DAO, including data
# related retreival via a DB for Baytechs.
#
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Include required libraries/modules
#-----------------------------------------------------------------------------
use lib "/path/to/library";
use strict;
use warnings FATAL => qw(all);
use Getopt::Long;
use Data::Dumper;
use OMX::Data::DAO;
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Global variable declaration
#-----------------------------------------------------------------------------
my ($dao, $debug, $ptnii_name, $db_baytechs);
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# -MAIN-
#-----------------------------------------------------------------------------
check_opts();
get_baytech();
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Method to setup a DAO (Data Access Orchestrator) Object
#-----------------------------------------------------------------------------
sub get_baytech
{
$dao = new OMX::Data::DAO(debug => $debug);
$dao->display;
my $bt_data = $dao->baytech_db(debug => $debug);
$bt_data->connect;
$bt_data->auto_disconnect(0);
#--------------------------------------------------
# Example, searching for all baytechs
#--------------------------------------------------
#$db_baytechs = $bt_data->find_all;
# print "Example: Search for all baytechs: \n";
# foreach my $item (@$db_baytechs)
# {
# print $item->{NAME}, " ", $item->{IP_ADDR}, " ", $item->{PHONE_NUM}, " ", $item->{REGION}, " ", $item->{IP_METHOD}, " ", $item->{ACTIVE},"\n";
# }
# print "\n\n";
#--------------------------------------------------
#--------------------------------------------------
# Example, searching for baytech by name
#--------------------------------------------------
$bt_data->search_value('baytech001');
$db_baytechs = $bt_data->find_by_name;
print "Example: Search using baytech name: \n";
&display_records;
#--------------------------------------------------
#--------------------------------------------------
# Example, searching for baytech via ip address
#--------------------------------------------------
$bt_data->search_value('1.6.0.6');
$db_baytechs = $bt_data->find_by_ip;
print "Example: Search using baytech ip address: \n";
&display_records;
#--------------------------------------------------
#--------------------------------------------------
# Example, searching for baytech via phone number
#--------------------------------------------------
$bt_data->search_value('9995551212');
$db_baytechs = $bt_data->find_by_phone;
print "Example: Search using baytech phone number: \n";
&display_records;
#--------------------------------------------------
#--------------------------------------------------
# Example, searching for baytech via device name
#--------------------------------------------------
$bt_data->search_value('$p_name');
$db_baytechs = $bt_data->find_by_device;
print "Example: Search using device name: \n";
&display_records;
#--------------------------------------------------
$bt_data->disconnect;
}
#-----------------------------------------------------------------------------
# Display records
#-----------------------------------------------------------------------------
sub display_records
{
foreach my $item (@$db_baytechs)
{
print $item->{NAME}, " ", $item->{IP_ADDR}, " ", $item->{PHONE_NUM}, " ", $item->{REGION}, " ", $item->{IP_METHOD}, " ", "\n";
}
print "\n\n";
print Dumper(@$db_baytechs) if $debug;
}
#-----------------------------------------------------------------------------
# Method to check that any required options have been supplied.
#-----------------------------------------------------------------------------
sub check_opts
{
Getopt::Long::config("pass_through");
GetOptions('debug' => \$debug,
'p_name:s' => \$p_name
);
if (!defined($p_name))
{
&usage;
}
}
#-----------------------------------------------------------------------------
# Displays a message to the user instructing what options are required.
#-----------------------------------------------------------------------------
sub usage
{
print "Usage t_baytech_db.pl\n";
print "-p_name [name] (*Required*)\n";
print "-debug [1|0] (-Optional)\n";
print "\n";
print "Example: t_baytech_db.pl -ptnii_name baytech001 -debug \n\n";
exit;
}
#-----------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment