1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
package Api::Ocsinventory::Restapi;
# For dev purpose only
# use lib "/usr/local/share/OCSInventory-Server/";
# use Data::Dumper;
# Framework uses
use Mojolicious::Lite;
# Common sub for api
require Api::Ocsinventory::Restapi::ApiCommon;
## Computer section
require Api::Ocsinventory::Restapi::Computer::Get::ComputerId; # Get specific Computer informations
require Api::Ocsinventory::Restapi::Computer::Get::ComputerIdField; # Get specific field of Computer
require Api::Ocsinventory::Restapi::Computer::Get::Computers; # Get list of Computers
require Api::Ocsinventory::Restapi::Computer::Get::ComputersListId; # Get list of Computers ID
require Api::Ocsinventory::Restapi::Computer::Get::ComputersSearch; # Get list of ID depending on search
## IPDiscover section
require Api::Ocsinventory::Restapi::Ipdiscover::Get::Ipdiscover;
require Api::Ocsinventory::Restapi::Ipdiscover::Get::IpdiscoverNetwork;
require Api::Ocsinventory::Restapi::Ipdiscover::Get::IpdiscoverTag;
## SNMP section
require Api::Ocsinventory::Restapi::Snmp::Get::SnmpId; # Get specific Snmp type informations
require Api::Ocsinventory::Restapi::Snmp::Get::SnmpIdField; # Get specific information by id of Snmp type
require Api::Ocsinventory::Restapi::Snmp::Get::SnmpListId; # Get list of Snmp Type
## Routes
get '/v1/computers/listID' => sub {
my $c = shift;
$c->render(format => 'json', text => Api::Ocsinventory::Restapi::Computer::Get::ComputersListId::get_computers_id());
};
get '/v1/computer/:id' => sub {
my $c = shift;
my $id = $c->stash('id');
$c->render(format => 'json', text => Api::Ocsinventory::Restapi::Computer::Get::ComputerId::get_computer($id));
};
get '/v1/computer/:id/:field' => sub {
my $c = shift;
my $id = $c->stash('id');
my $field = $c->stash('field');
my $where = $c->param('where')|| "";
my $operator = $c->param('operator')|| "";
my $value = $c->param('value')|| "";
$c->render(json => Api::Ocsinventory::Restapi::Computer::Get::ComputerIdField::get_computer_field($id, $field, $where, $operator, $value));
};
get '/v1/computers' => sub {
my $c = shift;
my $id = $c->stash('id');
my $start = $c->param('start')||0;
my $limit = $c->param('limit')||0;
$c->render(format => 'json', text => Api::Ocsinventory::Restapi::Computer::Get::Computers::get_computers($limit, $start));
};
get '/v1/computers/search' => sub {
my $c = shift;
my $params_hash = $c->req->params->to_hash;
$c->render(format => 'json', text => Api::Ocsinventory::Restapi::Computer::Get::ComputersSearch::get_computers_search($params_hash));
};
get '/v1/ipdiscover' => sub {
my $c = shift;
my $start = $c->param('start')||0;
my $limit = $c->param('limit')||0;
$c->render(format => 'json', text => Api::Ocsinventory::Restapi::Ipdiscover::Get::Ipdiscover::get_ipdiscovers($start, $limit));
};
get '/v1/ipdiscover/tag/:tag' => sub {
my $c = shift;
my $tag = $c->stash('tag');
$c->render(json => Api::Ocsinventory::Restapi::Ipdiscover::Get::IpdiscoverTag::get_ipdiscover_tag($tag));
};
get '/v1/ipdiscover/network/#network' => sub {
my $c = shift;
my $network = $c->stash('network');
$c->render(format => 'json', text => Api::Ocsinventory::Restapi::Ipdiscover::Get::IpdiscoverNetwork::get_ipdiscover_network($network));
};
get '/v1/snmps/typeList' => sub {
my $c = shift;
$c->render(json => Api::Ocsinventory::Restapi::Snmp::Get::SnmpListId::get_snmps_id());
};
get '/v1/snmp/:type' => sub {
my $c = shift;
my $type = $c->stash('type');
my $start = $c->param('start')||0;
my $limit = $c->param('limit')||0;
$c->render(json => Api::Ocsinventory::Restapi::Snmp::Get::SnmpId::get_snmp_id($type, $start, $limit));
};
get '/v1/snmp/:type/:id' => sub {
my $c = shift;
my $type = $c->stash('type');
my $id = $c->stash('id');
$c->render(json => Api::Ocsinventory::Restapi::Snmp::Get::SnmpIdField::get_snmp_field($type, $id));
};
app->start;
|