Merge branch '2016-plugin-monitorizacion-con-docker-swarm' into 'develop'
Minor fix in plugintools api_methods See merge request artica/pandorafms!1484
This commit is contained in:
commit
b620c1e7d9
|
@ -8822,6 +8822,40 @@ function api_get_agent_name($id_agent, $trash1, $trash2, $returnType) {
|
|||
returnData($returnType, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the ID or an hash of IDs of the detected given agents
|
||||
*
|
||||
* @param array or value $data
|
||||
*
|
||||
*
|
||||
**/
|
||||
function api_get_agent_id($trash1, $trash2, $data, $returnType) {
|
||||
$response;
|
||||
|
||||
if (is_metaconsole()) {
|
||||
return;
|
||||
}
|
||||
if (empty($returnType)) {
|
||||
$returnType = "json";
|
||||
}
|
||||
|
||||
$response = array();
|
||||
|
||||
if ($data["type"] == "array") {
|
||||
$response["type"] = "array";
|
||||
$response["data"] = array();
|
||||
|
||||
foreach ($data["data"] as $name) {
|
||||
$response["data"][$name] = agents_get_agent_id($name, 1);
|
||||
}
|
||||
} else {
|
||||
$response["type"] = "string";
|
||||
$response["data"] = agents_get_agent_id($data["data"], 1);
|
||||
}
|
||||
|
||||
returnData($returnType, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Agent alias for a given id
|
||||
*
|
||||
|
@ -10217,7 +10251,7 @@ function api_set_new_cluster($thrash1, $thrash2, $other, $thrash3) {
|
|||
db_pandora_audit("Report management", "Fail try to create agent");
|
||||
|
||||
returnData('string',
|
||||
array('type' => 'string', 'data' => (int)((bool)$id_cluster)));
|
||||
array('type' => 'string', 'data' => (int)$id_cluster));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10266,7 +10300,7 @@ function api_set_new_cluster($thrash1, $thrash2, $other, $thrash3) {
|
|||
//
|
||||
if($element["type"] == "AA"){
|
||||
//
|
||||
$tcluster_module = db_process_sql_insert('tcluster_item',array('name'=>$element["name"],'id_cluster'=>$element["id_cluster"],'critical_limit'=>$element["critical_limit"],'warning_limit'=>$element["warning_limit"]));
|
||||
$tcluster_module = db_process_sql_insert('tcluster_item',array('name'=>io_safe_input($element["name"]),'id_cluster'=>$element["id_cluster"],'critical_limit'=>$element["critical_limit"],'warning_limit'=>$element["warning_limit"]));
|
||||
|
||||
$id_agent = db_process_sql('select id_agent from tcluster where id = '.$element["id_cluster"]);
|
||||
|
||||
|
@ -10285,7 +10319,7 @@ function api_set_new_cluster($thrash1, $thrash2, $other, $thrash3) {
|
|||
$get_module_interval_value = $get_module_type[0]['module_interval'];
|
||||
|
||||
$values_module = array(
|
||||
'nombre' => $element["name"],
|
||||
'nombre' => io_safe_input($element["name"]),
|
||||
'id_modulo' => 0,
|
||||
'prediction_module' => 6,
|
||||
'id_agente' => $id_agent[0]['id_agent'],
|
||||
|
|
|
@ -40,6 +40,7 @@ our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
|||
|
||||
our @EXPORT = qw(
|
||||
api_available
|
||||
api_call
|
||||
api_create_custom_field
|
||||
api_create_tag
|
||||
api_create_group
|
||||
|
@ -50,11 +51,12 @@ our @EXPORT = qw(
|
|||
extract_dbpass
|
||||
extract_key_map
|
||||
get_addresses
|
||||
get_current_utime_milis
|
||||
get_lib_version
|
||||
get_unit
|
||||
get_unix_time
|
||||
get_sys_environment
|
||||
get_current_utime_milis
|
||||
get_value_translated
|
||||
getCurrentUTimeMilis
|
||||
head
|
||||
in_array
|
||||
|
@ -295,6 +297,37 @@ sub get_unit {
|
|||
return $str;
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Get unit
|
||||
################################################################################
|
||||
sub get_value_translated {
|
||||
my $str = shift;
|
||||
|
||||
if (empty($str)) {
|
||||
return $str;
|
||||
}
|
||||
$str = trim($str);
|
||||
|
||||
my $value = $str;
|
||||
my $unit = get_unit($str);
|
||||
if(empty($unit)) {
|
||||
return $str;
|
||||
}
|
||||
|
||||
$value =~ s/$unit//g;
|
||||
|
||||
if ($unit =~ /kb/i) { return $value * (2**10);}
|
||||
if ($unit =~ /kib/i) { return $value * (2**10);}
|
||||
if ($unit =~ /mb/i) { return $value * (2**20);}
|
||||
if ($unit =~ /mib/i) { return $value * (2**20);}
|
||||
if ($unit =~ /gb/i) { return $value * (2**30);}
|
||||
if ($unit =~ /gib/i) { return $value * (2**30);}
|
||||
if ($unit =~ /tb/i) { return $value * (2**40);}
|
||||
|
||||
return $value;
|
||||
|
||||
}
|
||||
|
||||
################################################################################
|
||||
## Decodes a json strin into an hash
|
||||
################################################################################
|
||||
|
@ -1433,10 +1466,10 @@ sub api_available {
|
|||
($api_url, $api_pass, $api_user, $api_user_pass) = @{$apidata};
|
||||
}
|
||||
|
||||
$api_url = $conf->{'api_url'} unless empty($api_url);
|
||||
$api_pass = $conf->{'api_pass'} unless empty($api_pass);
|
||||
$api_user = $conf->{'api_user'} unless empty($api_user);
|
||||
$api_user_pass = $conf->{'api_user_pass'} unless empty($api_user_pass);
|
||||
$api_url = $conf->{'api_url'} if empty($api_url);
|
||||
$api_pass = $conf->{'api_pass'} if empty($api_pass);
|
||||
$api_user = $conf->{'api_user'} if empty($api_user);
|
||||
$api_user_pass = $conf->{'api_user_pass'} if empty($api_user_pass);
|
||||
|
||||
my $op = "get";
|
||||
my $op2 = "test";
|
||||
|
@ -1460,7 +1493,83 @@ sub api_available {
|
|||
id => (empty($rs)?undef:trim($rs))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#########################################################################################
|
||||
# Pandora API call
|
||||
# apidata->{other} = [field1,field2,...,fieldi,...,fieldn]
|
||||
#########################################################################################
|
||||
sub api_call {
|
||||
my ($conf, $apidata) = @_;
|
||||
my ($api_url, $api_pass, $api_user, $api_user_pass,
|
||||
$op, $op2, $other_mode, $other, $return_type);
|
||||
my $separator;
|
||||
|
||||
if (ref $apidata eq "ARRAY") {
|
||||
($api_url, $api_pass, $api_user, $api_user_pass,
|
||||
$op, $op2, $return_type, $other_mode, $other) = @{$apidata};
|
||||
}
|
||||
if (ref $apidata eq "HASH") {
|
||||
$api_url = $apidata->{'api_url'};
|
||||
$api_pass = $apidata->{'api_pass'};
|
||||
$api_user = $apidata->{'api_user'};
|
||||
$api_user_pass = $apidata->{'api_user_pass'};
|
||||
$op = $apidata->{'op'};
|
||||
$op2 = $apidata->{'op2'};
|
||||
$return_type = $apidata->{'return_type'};
|
||||
$other_mode = "url_encode_separator_" . $apidata->{'url_encode_separator'} unless empty($apidata->{'url_encode_separator'});
|
||||
$other_mode = "url_encode_separator_|" if empty($other_mode);
|
||||
($separator) = $other_mode =~ /url_encode_separator_(.*)/;
|
||||
}
|
||||
|
||||
$api_url = $conf->{'api_url'} if empty($api_url);
|
||||
$api_pass = $conf->{'api_pass'} if empty($api_pass);
|
||||
$api_user = $conf->{'api_user'} if empty($api_user);
|
||||
$api_user_pass = $conf->{'api_user_pass'} if empty($api_user_pass);
|
||||
$op = $conf->{'op'} if empty($op);
|
||||
$op2 = $conf->{'op2'} if empty($op2);
|
||||
$return_type = $conf->{'return_type'} if empty($return_type);
|
||||
$return_type = 'json' if empty($return_type);
|
||||
if (ref ($apidata->{'other'}) eq "ARRAY") {
|
||||
$other_mode = "url_encode_separator_|" if empty($other_mode);
|
||||
($separator) = $other_mode =~ /url_encode_separator_(.*)/;
|
||||
|
||||
if (empty($separator)) {
|
||||
$separator = "|";
|
||||
$other_mode = "url_encode_separator_|";
|
||||
}
|
||||
|
||||
$other = join $separator, @{$apidata->{'other'}};
|
||||
}
|
||||
else {
|
||||
$other = $apidata->{'other'};
|
||||
}
|
||||
|
||||
my $call;
|
||||
|
||||
$call = $api_url . '?';
|
||||
$call .= 'op=' . $op . '&op2=' . $op2;
|
||||
$call .= '&other_mode=url_encode_separator_' . $separator;
|
||||
$call .= '&other=' . $other;
|
||||
$call .= '&apipass=' . $api_pass . '&user=' . $api_user . '&pass=' . $api_user_pass;
|
||||
$call .= '&return_type=' . $return_type;
|
||||
|
||||
my $rs = call_url($conf, "$call");
|
||||
|
||||
if (ref($rs) ne "HASH") {
|
||||
return {
|
||||
rs => (empty($rs)?1:0),
|
||||
error => (empty($rs)?"Empty response.":undef),
|
||||
id => (empty($rs)?undef:trim($rs)),
|
||||
response => (empty($rs)?undef:$rs),
|
||||
}
|
||||
}
|
||||
else {
|
||||
return {
|
||||
rs => 1,
|
||||
error => $rs->{'error'},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#########################################################################################
|
||||
|
@ -1473,10 +1582,10 @@ sub api_create_custom_field {
|
|||
($api_url, $api_pass, $api_user, $api_user_pass) = @{$apidata};
|
||||
}
|
||||
|
||||
$api_url = $conf->{'api_url'} unless empty($api_url);
|
||||
$api_pass = $conf->{'api_pass'} unless empty($api_pass);
|
||||
$api_user = $conf->{'api_user'} unless empty($api_user);
|
||||
$api_user_pass = $conf->{'api_user_pass'} unless empty($api_user_pass);
|
||||
$api_url = $conf->{'api_url'} if empty($api_url);
|
||||
$api_pass = $conf->{'api_pass'} if empty($api_pass);
|
||||
$api_user = $conf->{'api_user'} if empty($api_user);
|
||||
$api_user_pass = $conf->{'api_user_pass'} if empty($api_user_pass);
|
||||
|
||||
|
||||
|
||||
|
@ -1572,10 +1681,10 @@ sub api_create_tag {
|
|||
($api_url, $api_pass, $api_user, $api_user_pass) = @{$apidata};
|
||||
}
|
||||
|
||||
$api_url = $conf->{'api_url'} unless empty($api_url);
|
||||
$api_pass = $conf->{'api_pass'} unless empty($api_pass);
|
||||
$api_user = $conf->{'api_user'} unless empty($api_user);
|
||||
$api_user_pass = $conf->{'api_user_pass'} unless empty($api_user_pass);
|
||||
$api_url = $conf->{'api_url'} if empty($api_url);
|
||||
$api_pass = $conf->{'api_pass'} if empty($api_pass);
|
||||
$api_user = $conf->{'api_user'} if empty($api_user);
|
||||
$api_user_pass = $conf->{'api_user_pass'} if empty($api_user_pass);
|
||||
|
||||
my $op = "set";
|
||||
my $op2 = "create_tag";
|
||||
|
|
Loading…
Reference in New Issue