Skip to content

Commit

Permalink
fix(broker): rrd files had bad permissions after rebuild (#1090)
Browse files Browse the repository at this point in the history
REFS: MON-34596
  • Loading branch information
jean-christophe81 authored Feb 1, 2024
1 parent 982af9c commit 55ecf41
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
17 changes: 17 additions & 0 deletions broker/rrd/src/creator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,23 @@ void creator::_open(std::string const& filename,
if (rrd_create_r(filename.c_str(), 1, from, argc, argv))
throw exceptions::open("RRD: could not create file '{}: {}", filename,
rrd_get_error());

// by default rrd_create_r create rw-r----- files group write is mandatory
// for rrdcached
struct stat rrd_file_stat;
if (stat(filename.c_str(), &rrd_file_stat)) {
SPDLOG_LOGGER_ERROR(log_v2::rrd(), "RRD: fail to access rights of {}",
filename);
return;
}

if ((rrd_file_stat.st_mode & (S_IWGRP | S_IRGRP)) !=
(S_IWGRP | S_IRGRP)) { // add group rw right
if (!chmod(filename.c_str(), rrd_file_stat.st_mode | S_IWGRP | S_IRGRP)) {
SPDLOG_LOGGER_ERROR(
log_v2::rrd(), "RRD: fail to add group rights (660) of {}", filename);
}
}
}

/**
Expand Down
5 changes: 4 additions & 1 deletion tests/broker-engine/rrd.robot
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,10 @@ BRRDRMU1
${result} Compare RRD Average Value ${m} ${value}
Should Be True
... ${result}
... msg=Data before RRD rebuild contain alternatively the metric ID and 0. The expected average is metric_id / 2.
... Data before RRD rebuild contain alternatively the metric ID and 0. The expected average is metric_id / 2.
# 48 = 60(octal)
${result} Has File Permissions ${VarRoot}/lib/centreon/metrics/${m}.rrd 48
Should Be True ${result} ${VarRoot}/lib/centreon/metrics/${m}.rrd has not RW group permission
END

Rrd_1
Expand Down
14 changes: 14 additions & 0 deletions tests/resources/Common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,3 +1137,17 @@ def wait_until_file_modified(path: str, date: str, timeout: int = TIMEOUT):

logger.console(f"{path} not modified since {date}")
return False

def has_file_permissions(path: str, permission: int):
"""! test if file has permission passed in parameter
it does a AND with permission parameter
@param path path of the file
@permission mask to test file permission
@return True if the file has the requested permissions
"""
stat_res= os.stat(path)
if stat_res is None:
logger.console(f"fail to get permission of {path}")
return False
masked = stat_res.st_mode & permission
return masked == permission

0 comments on commit 55ecf41

Please sign in to comment.