Skip to content

Commit d773128

Browse files
authored
feat(apps::backup::rubkrik::graphql::plugin): new plugin (#6180)
Refs: CTOR-2250
1 parent 57fe495 commit d773128

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/apps/backup/rubrik/graphql/mode/jobs.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use warnings;
2727

2828
use DateTime;
2929
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
30-
use centreon::plugins::misc qw/is_excluded change_seconds flatten_arrays/;
30+
use centreon::plugins::misc qw/is_excluded change_seconds flatten_arrays disco_escape/;
3131
use apps::backup::rubrik::graphql::common qw/timerange_check_options $timerange_filters/;
3232
use centreon::plugins::constants qw(:counters);
3333
use POSIX qw/floor/;
@@ -416,7 +416,7 @@ sub disco_show {
416416

417417
foreach my $job (@{$jobs}) {
418418
$self->{output}->add_disco_entry(
419-
jobId => $job->{fid}, jobName => $job->{objectName}, jobType => $job->{lastActivityType}, locationName => $job->{location} // ''
419+
jobId => $job->{fid}, jobName => disco_escape($job->{objectName}), jobType => $job->{lastActivityType}, locationName => disco_escape($job->{location} // '')
420420
);
421421
}
422422
}

src/centreon/plugins/misc.pm

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ our @EXPORT_OK = qw/change_seconds
3737
check_security_whitelist
3838
convert_bytes
3939
date_xm_ago_utc
40+
disco_escape
4041
execute
4142
flatten_arrays
4243
flatten_to_hash
@@ -1076,6 +1077,15 @@ sub date_xm_ago_utc {
10761077
return sprintf( "%04d-%02d-%02dT%02d:%02d:%02dZ", $t[5] + 1900, $t[4] + 1, $t[3], $t[2], $t[1], $t[0]);
10771078
}
10781079

1080+
# Escape a string to be used by the discovery module
1081+
sub disco_escape($;$) {
1082+
my ($value, $sub) = @_;
1083+
1084+
$sub //= '_';
1085+
1086+
return $value =~ s/[~!\$%\^&\*"'\|<>?,()=]/$sub/gr;
1087+
}
1088+
10791089
1;
10801090

10811091
__END__
@@ -1758,6 +1768,20 @@ Attempts to format a MAC address into a human-readable format
17581768
17591769
=back
17601770
1771+
=head2 disco_escape
1772+
1773+
my $value = centreon::plugins::misc::disco_escape($value, $sub);
1774+
1775+
Replace characters not allowed by centengine/discovery with $sub
1776+
1777+
=over 4
1778+
1779+
=item * C<$value> - label
1780+
1781+
=item * C<$sub> - replacement character ( default: '_' )
1782+
1783+
=back
1784+
17611785
=head2 json_to_sha256
17621786
17631787
my $hash = centreon::plugins::misc::json_to_sha256(%options);

0 commit comments

Comments
 (0)