Ivan Berezovskiy | 45570a2 | 2019-07-04 17:00:26 +0400 | [diff] [blame^] | 1 | import logging |
| 2 | |
| 3 | logger = logging.getLogger(__name__) |
| 4 | |
| 5 | def __virtual__(): |
| 6 | ''' |
| 7 | Only load if jenkins_common module exist. |
| 8 | ''' |
| 9 | if 'jenkins_common.call_groovy_script' not in __salt__: |
| 10 | return ( |
| 11 | False, |
| 12 | 'The jenkins_audittrail state module cannot be loaded: ' |
| 13 | 'jenkins_common not found') |
| 14 | return True |
| 15 | |
| 16 | def config (name, type="console", log="", limit=0, count=0, output="STD_OUT", |
| 17 | date_format="yyyy-MM-dd HH:mm:ss:SSS", log_prefix="", syslog_server_hostname="", |
| 18 | syslog_server_port=514, syslog_facility="SYSLOG", |
| 19 | app_name="jenkins", message_hostname="", message_format="RFC_3164"): |
| 20 | """ |
| 21 | Jenkins AuditTrail logging config state method |
| 22 | |
| 23 | :param type: logger type. one of: console (default), file, syslog |
| 24 | Console Logger params: |
| 25 | :param output: STD_OUT or STD_ERR |
| 26 | :param date_format |
| 27 | :param log_prefix |
| 28 | File Logger params: |
| 29 | :param log: path to log file |
| 30 | :param limit: log file size |
| 31 | :param count: log file count to keep |
| 32 | Syslog Logger params: |
| 33 | :param syslog_server_hostname |
| 34 | :param syslog_server_port |
| 35 | :param syslog_facility |
| 36 | :param app_name |
| 37 | :param message_hostname |
| 38 | :param message_format: RFC_3164 or RFC_5424 |
| 39 | |
| 40 | :returns: salt-specified state dict |
| 41 | """ |
| 42 | |
| 43 | template = __salt__['jenkins_common.load_template']( |
| 44 | 'salt://jenkins/files/groovy/audittrail_config.template', |
| 45 | __env__) |
| 46 | return __salt__['jenkins_common.api_call'](name, template, |
| 47 | ["CREATED", "EXISTS"], |
| 48 | { |
| 49 | 'logger_type': type, |
| 50 | 'output': output, |
| 51 | 'date_format': date_format, |
| 52 | 'log_prefix': log_prefix if log_prefix else "", |
| 53 | 'log': log if log else "", |
| 54 | 'limit': limit, |
| 55 | 'count': count, |
| 56 | 'syslog_server_hostname': syslog_server_hostname if syslog_server_hostname else "", |
| 57 | 'syslog_server_port': syslog_server_port, |
| 58 | 'syslog_facility': syslog_facility, |
| 59 | 'app_name': app_name, |
| 60 | 'message_hostname': message_hostname if message_hostname else "", |
| 61 | 'message_format': message_format if message_format else "", |
| 62 | }, |
| 63 | 'AuditTrail logger configuration') |
| 64 | |
| 65 | def params (name, pattern="", log_build_cause=True): |
| 66 | """ |
| 67 | Jenkins AuditTrail logging params state method |
| 68 | |
| 69 | :param pattern |
| 70 | :param log_build_cause |
| 71 | |
| 72 | :returns: salt-specified state dict |
| 73 | """ |
| 74 | |
| 75 | template = __salt__['jenkins_common.load_template']( |
| 76 | 'salt://jenkins/files/groovy/audittrail_params.template', |
| 77 | __env__) |
| 78 | return __salt__['jenkins_common.api_call'](name, template, |
| 79 | ["CHANGED", "EXISTS"], |
| 80 | { |
| 81 | 'pattern': pattern if pattern else "", |
| 82 | 'log_build_cause': str(log_build_cause).lower(), |
| 83 | }, |
| 84 | 'AuditTrail logger params') |