1"""
2Icinga2 Common Utils
3=================
4
5This module provides common functionality for icinga2 module and state.
6
7.. versionadded:: 2018.8.3
8"""
9
10import logging
11import re
12
13import salt.modules.cmdmod
14import salt.utils.path
15
16__salt__ = {"cmd.run_all": salt.modules.cmdmod.run_all}
17log = logging.getLogger(__name__)
18
19
20def get_certs_path():
21    icinga2_output = __salt__["cmd.run_all"](
22        [salt.utils.path.which("icinga2"), "--version"], python_shell=False
23    )
24    version = re.search(r"r\d+\.\d+", icinga2_output["stdout"]).group(0)
25    # Return new certs path for icinga2 >= 2.8
26    if int(version.split(".")[1]) >= 8:
27        return "/var/lib/icinga2/certs/"
28    # Keep backwords compatibility with older icinga2
29    return "/etc/icinga2/pki/"
30