Skip to content

Commit

Permalink
(stream/lib) add output limit (#112)
Browse files Browse the repository at this point in the history
* (stream/lib) add output limit

* fixing my dumb mistakes

* fix bad variable scope
  • Loading branch information
tanguyvda committed Jun 13, 2022
1 parent b23d8db commit b95a90f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions modules/centreon-stream-connectors-lib/sc_event.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,10 @@ function ScEvent:build_outputs()
self.event.output = string.gsub(self.event.output, "\n", self.params.output_line_break_replacement_character)
end

if self.params.output_size_limit ~= "" then
self.event.output = string.sub(self.event.output, 1, self.params.output_size_limit)
end

end

--- is_valid_storage: DEPRECATED method, use NEB category to get metric data instead
Expand Down
4 changes: 3 additions & 1 deletion modules/centreon-stream-connectors-lib/sc_params.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ function sc_params.new(common, logger)
use_long_output = 1,
remove_line_break_in_output = 1,
output_line_break_replacement_character = " ",
output_size_limit = "",

-- time parameters
local_time_diff_from_utc = os.difftime(os.time(), os.time(os.date("!*t", os.time()))),
Expand Down Expand Up @@ -784,6 +785,7 @@ function ScParams:check_params()
self.params.output_line_break_replacement_character = self.common:if_wrong_type(self.params.output_line_break_replacement_character, "string", " ")
self.params.metric_name_regex = self.common:if_wrong_type(self.params.metric_name_regex, "string", "")
self.params.metric_replacement_character = self.common:ifnil_or_empty(self.params.metric_replacement_character, "_")
self.params.output_size_limit = self.common:if_wrong_type(self.params.output_size_limit, "number", "")
end

--- get_kafka_params: retrieve the kafka parameters and store them the self.params.kafka table
Expand Down Expand Up @@ -858,7 +860,7 @@ function ScParams:load_event_format_file(json_string)
end

function ScParams:build_accepted_elements_info()
categories = self.params.bbdo.categories
local categories = self.params.bbdo.categories
self.params.accepted_elements_info = {}

-- list all accepted elements
Expand Down
3 changes: 2 additions & 1 deletion modules/docs/sc_param.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ The sc_param module provides methods to help you handle parameters for your stre
| allow_insecure_connection | number | 0 | check the certificate validity of the peer host (0 = needs to be a valid certificate), use 1 if you are using self signed certificates | | |
| use_long_output | number | 1 | use the long output when sending an event (set to 0 to send the short output) | service_status(neb), host_status(neb) | |
| remove_line_break_in_output | number | 1 | replace all line breaks (\n) in the output with the character set in the output_line_break_replacement_character parameter | service_status(neb), host_status(neb) | |
| output_line_break_replacement_character | string | " " | replace all replace line break with this parameter value in the output (default value is a blank space) | service_status(neb), host_status(neb) | |
| output_line_break_replacement_character | string | " " | replace all replace line break with this parameter value in the output (default value is a blank space) | service_status(neb), host_status(neb) |
| output_size_limit | number | "" | put a character number limit for the output (no limit by default) | service_status(neb), host_status(neb) | |
| metric_name_regex | string | "" | the regex that will be used to transform the metric name to a compatible name for the software that will receive the data | service_status(neb), host_status(neb) | |
| metric_replacement_character | string | "_" | the character that will be used to replace invalid characters in the metric name | service_status(neb), host_status(neb) | |
| logfile | string | **check the stream connector documentation** | the logfile that will be used for the stream connector | any | |
Expand Down

0 comments on commit b95a90f

Please sign in to comment.