From e9bd64698355398ede8724ce196affaa823d2a45 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 30 Apr 2020 15:19:19 +0200 Subject: [PATCH] added missing function read_file --- pandora_server/lib/PandoraFMS/PluginTools.pm | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pandora_server/lib/PandoraFMS/PluginTools.pm b/pandora_server/lib/PandoraFMS/PluginTools.pm index 07e2324d59..e403fc3060 100644 --- a/pandora_server/lib/PandoraFMS/PluginTools.pm +++ b/pandora_server/lib/PandoraFMS/PluginTools.pm @@ -87,6 +87,7 @@ our @EXPORT = qw( print_warning print_stderror read_configuration + read_file simple_decode_json snmp_data_switcher snmp_get @@ -1263,6 +1264,27 @@ sub read_configuration { return $config; } +################################################################################ +## Reads a file and returns entire content or undef if error. +################################################################################ +sub read_file { + my $path = shift; + + my $_FILE; + if( !open($_FILE, "<", $path) ) { + # failed to open, return undef + return undef; + } + + # Slurp configuration file content. + my $content = do { local $/; <$_FILE> }; + + # Close file + close($_FILE); + + return $content; +} + ################################################################################ # General arguments parser ################################################################################