Skip to content

Commit

Permalink
Re-enable consider-using-max check.
Browse files Browse the repository at this point in the history
Change-Id: I9ea65d6563898aa5241433e7619605ccca92aeb9
  • Loading branch information
spt29 committed May 25, 2021
1 parent c2706ac commit 9c07a12
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 35 deletions.
1 change: 0 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ disable=
R0801,
#---------------------------------------------------------------------------
# Emergency suppressions, must be removed SOON!
consider-using-max-builtin,
consider-using-with,

enable=
Expand Down
4 changes: 1 addition & 3 deletions checks/jira_custom_svc
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ def _get_value_diff(diff_name, svc_value, timespan):

# Get previous value and time difference
last_time, last_val = old_state
timedif = this_time - last_time
if timedif < 0:
timedif = 0
timedif = max(this_time - last_time, 0)
if timedif < float(timespan):
diff_val = svc_value - last_val
else:
Expand Down
9 changes: 3 additions & 6 deletions checks/windows_updates
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,17 @@ def check_windows_updates(_no_item, params, info):
this_txt = '%d %s updates' % (cur, label)
if crit and cur >= crit:
this_txt += ' >=%d (!!)' % crit
if status < 2:
status = 2
status = max(status, 2)
elif warn and cur >= warn:
this_txt += ' >=%d (!)' % warn
if status < 1:
status = 1
status = max(status, 1)
if label == 'important' and cur > 0 and verbose:
this_txt += ', (%s) --- ' % updates
txt.append(this_txt)
perfdata.append((label, cur, warn, crit))

if reboot_required == 1:
if status < 1:
status = 1
status = max(status, 1)
txt.append('Reboot required to finish updates(!)')

if forced_reboot != "":
Expand Down
4 changes: 1 addition & 3 deletions cmk/base/check_legacy_includes/graylog.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ def _get_value_diff(diff_name, svc_value, timespan):

# Get previous value and time difference
last_time, last_val = old_state
timedif = this_time - last_time
if timedif < 0:
timedif = 0
timedif = max(this_time - last_time, 0)
if timedif < float(timespan):
diff_val = svc_value - last_val
else:
Expand Down
4 changes: 2 additions & 2 deletions cmk/base/parent_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def do_scan_parents(hosts: List[HostName]) -> None:
parent_rules = []
gateway_hosts: Set[HostName] = set()

if config.max_num_processes < 1:
config.max_num_processes = 1
# TODO: Sneakily changing a global variable looks like a bad idea!
config.max_num_processes = max(config.max_num_processes, 1)

outfilename = cmk.utils.paths.check_mk_config_dir + "/parents.mk"

Expand Down
6 changes: 1 addition & 5 deletions cmk/base/plugins/agent_based/oracle_asm_diskgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,7 @@ def check_oracle_asm_diskgroup(item: str, params: Mapping[str, Any],
free_space_mb = int(free_mb) // dg_sizefactor

if params.get('req_mir_free'):
req_mir_free_mb = int(req_mir_free_mb)
if req_mir_free_mb < 0:
# requirred mirror free space could be negative!
req_mir_free_mb = 0

req_mir_free_mb = max(int(req_mir_free_mb), 0) # requirred mirror free space could be negative!
add_text = ', required mirror free space used'

result_list = list(
Expand Down
6 changes: 2 additions & 4 deletions cmk/base/plugins/agent_based/utils/df.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,8 @@ def get_filesystem_levels(size_gb: float, params: Mapping[str, Any]) -> Dict[str

# Make sure, levels do never get too low due to magic factor
lowest_warning_level, lowest_critical_level = levels["levels_low"]
if warn_scaled < lowest_warning_level:
warn_scaled = lowest_warning_level
if crit_scaled < lowest_critical_level:
crit_scaled = lowest_critical_level
warn_scaled = max(warn_scaled, lowest_warning_level)
crit_scaled = max(crit_scaled, lowest_critical_level)

else:
if not isinstance(warn, float):
Expand Down
6 changes: 1 addition & 5 deletions cmk/base/plugins/agent_based/utils/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,7 @@ def to_mem_used(self) -> Dict[str, int]:
# https://github.com/google/cadvisor/blob/c6ad44633aa0cee60a28430ddec632dca53becac/container/libcontainer/handler.go#L823
# https://github.com/containerd/cri/blob/bc08a19f3a44bda9fd141e6ee4b8c6b369e17e6b/pkg/server/container_stats_list_linux.go#L123
# https://github.com/docker/cli/blob/70a00157f161b109be77cd4f30ce0662bfe8cc32/cli/command/container/stats_helpers.go#L245
container_memory_usage = self.mem_usage - self.mem_cache

if container_memory_usage < 0:
container_memory_usage = 0

container_memory_usage = max(self.mem_usage - self.mem_cache, 0)
return {
"MemTotal": self.mem_total,
"MemFree": self.mem_total - container_memory_usage,
Expand Down
4 changes: 1 addition & 3 deletions cmk/gui/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,7 @@ def get_stack_from_values(value: Union[str, int, float], half_value: Union[int,
half_value = float(half_value)
h = math.log(half_value, base) # value to be displayed at 50%
pos = 50 + 10.0 * (math.log(value, base) - h)
if pos < 2:
pos = 2
pos = min(pos, 98)
pos = min(max(2, pos), 98)

return [(pos, color), (100 - pos, get_themed_perfometer_bg_color())]

Expand Down
4 changes: 1 addition & 3 deletions cmk/gui/plugins/views/perfometers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ def calculate_half_row_logarithmic(left_or_right, value, color, half_value, base
half_value = float(half_value)
h = math.log(half_value, base) # value to be displayed at 50%
pos = 25 + 10.0 * (math.log(value, base) - h)
if pos < 1:
pos = 1
pos = min(pos, 49)
pos = min(max(1, pos), 49)
if left_or_right == "right":
return [(pos, color), (50 - pos, get_themed_perfometer_bg_color())]
return [(50 - pos, get_themed_perfometer_bg_color()), (pos, color)]
Expand Down

0 comments on commit 9c07a12

Please sign in to comment.