def get_config(self) -> str:
        config = 'template Host "servertemplate_' + self.__id + '" {\n'

        for template in self.__templates:
            config += '  import "servertemplate_' + template.get_id() + '"\n'

        if None is not self.__ssh_template:
            config += '  import "sshtemplate_' + self.__ssh_template.get_id(
            ) + '"\n'

        if None is not self.__os:
            config += '  import "os_' + self.__os.get_id() + '"\n'

        for manager in self.__package_manager:
            config += '  import "packagemanager_' + manager.get_id() + '"\n'

        config += Checkable.get_config(self)
        config += ValueMapper.parse_var('address', self.__ipv4)
        config += ValueMapper.parse_var('address6', self.__ipv6)
        config += ValueMapper.parse_var('vars.checks', self.__checks)
        config += ValueMapper.parse_var('vars.groups',
                                        self.__groups,
                                        value_prefix='hostgroup_')
        config += PluginDirs.get_config(self)
        config += ScriptDirs.get_config(self)
        config += CustomVars.get_config(self)

        config += '  check_command = "hostalive"\n'
        config += '  zone = "' + self.__execution_zone.get_id() + '"\n'
        config += ValueMapper.parse_var('vars.endpoint_name',
                                        self.__execution_endpoint)
        config += '}\n'

        return config
Example #2
0
    def group_config_function(self, group):
        if 0 == len(group.get_telegram_id()):
            return []

        if None is self.__api_token:
            raise Exception('Telegram API token not set in ' + self.get_id())
        config = [
            ValueMapper.parse_var('vars.notification_telegram_groups', group.get_telegram_id()) + '\n' +
            ValueMapper.parse_var('vars.notification_telegram_token', self.__api_token) + '\n'
        ]
        return config
Example #3
0
    def get_config(self) -> str:
        self.validate()

        config = 'object User "user_' + self.__id + '" {\n'
        config += ValueMapper.parse_var('display_name', self.__display_name)
        config += Nameable.get_config(self)
        config += NotificationFunctions.get_config(self)
        config += ValueMapper.parse_var('groups', self.__groups, value_prefix='usergroup_')
        config += ValueMapper.parse_var('states', self.__states)
        config += ValueMapper.parse_var('types', self.__types)

        for var in self.__vars:
            config += '  var.' + var[0] + ' = ' + ValueMapper.parse_value_for_var(var[1]) + '\n'
        config += '}\n'

        return config
Example #4
0
    def get_custom_config(self) -> str:
        config = NmapScanUDP.get_config(self)
        config += NmapScanTCP.get_config(self)
        config += NmapN.get_config(self)
        config += Nmapr.get_config(self)
        config += NmapSystemDns.get_config(self)
        config += NmapTraceroute.get_config(self)
        config += NmapF.get_config(self)
        config += NmapR.get_config(self)
        config += NmapSV.get_config(self)
        config += NmapVersionLight.get_config(self)
        config += NmapVersionAll.get_config(self)
        config += NmapVersionTrace.get_config(self)
        config += NmapSC.get_config(self)
        config += NmapScriptTrace.get_config(self)
        config += NmapO.get_config(self)
        config += NmapOsscanGuess.get_config(self)
        config += NmapBadsum.get_config(self)
        config += Nmap6.get_config(self)
        config += NmapA.get_config(self)
        config += NmapSendEth.get_config(self)
        config += NmapSendIp.get_config(self)
        config += NmapPrivileged.get_config(self)
        config += NmapPn.get_config(self)
        config += NmapUnprivileged.get_config(self)
        config += ValueMapper.parse_var('vars.allowed_ports',
                                        self.__allowed_ports)
        config += NmapBase.get_custom_config(self)

        return config
Example #5
0
    def get_config(self) -> str:
        config = ''

        for custom_var in self.__custom_vars:
            if not custom_var['internal_use']:
                config += ValueMapper.parse_var('vars.' + custom_var['key'], custom_var['value'])

        return config
    def get_config(self: T) -> str:
        self.validate()

        config = Dependency.get_config(self)
        config += 'apply Dependency "servicedependency_' + self.get_id() + '" to Service {\n'
        config += '  import "dependency_' + self.get_id() + '"\n'
        config += ValueMapper.parse_var('parent_service_name', self.__parent_service_name)
        config += '  assign where "dependency_' + self.get_id() + '" in service.vars.dependencies\n'
        config += '}\n'

        return config
 def get_assign_config(self,
                       custom_config,
                       notification_id,
                       users=None,
                       groups=None):
     config = ''
     for type in ['Host', 'Service']:
         config += 'apply Notification "' + type.lower(
         ) + '_' + notification_id + '" to ' + type + ' {\n'
         config += '  import "notification_template_' + type.lower() + '_' \
                   + Notification.get_id(self) + '"\n'
         config += ValueMapper.parse_var('user_groups',
                                         groups,
                                         value_prefix='usergroup_')
         config += ValueMapper.parse_var('users',
                                         users,
                                         value_prefix='user_')
         config += custom_config
         config += '  assign where "notification_' + self.get_id() + '" in ' \
                   + type.lower() + '.vars.notification\n'
         config += '}\n'
     return config
    def get_config(self: T) -> str:
        self.validate()
        config = ''
        for type in ['Host', 'Service']:

            config += 'apply ScheduledDowntime "downtime_' + self.__id + '" to ' + type + '{\n'
            config += ValueMapper.parse_var('comment', self.__comment)
            config += ValueMapper.parse_var('author', self.__author)
            config += ValueMapper.parse_var('child_options', self.__child_options)
            config += ValueMapper.parse_var('fixed', self.__fixed)
            if None is not self.__duration:
                config += '  duration = ' + self.__duration + '\n'

            if 0 < len(self.__ranges):
                config += '  ranges = {\n'
                for range in self.__ranges:
                    config += '    "' + range[0] + '" = "' + range[1] + '"\n'
                config += '  }\n'

            config += '  assign where "downtime_' + self.__id + '" in ' + type.lower() + '.vars.downtime\n'
            config += '}\n'

        return config
    def get_config(self) -> str:
        self.validate()

        config = 'template Notification "notification_template_host_' + self.__id + '" {\n'
        config += '  interval = ' + self.__interval + '\n'

        if None is not self.__escalation:
            config += '  times = {\n'
            config += '    begin = ' + self.__escalation[0] + '\n'
            config += '    end = ' + self.__escalation[1] + '\n'
            config += '  }\n'

        config += ValueMapper.parse_var('command',
                                        self.__command,
                                        value_prefix='command_host_')
        config += ValueMapper.parse_var('period',
                                        self.__time_period,
                                        value_prefix='time_period_')
        config += ValueMapper.parse_var('types', self.__host_types)
        config += ValueMapper.parse_var('states', self.__host_states)
        config += '}\n'
        config += 'template Notification "notification_template_service_' + self.__id + '" {\n'
        config += '  interval = ' + self.__interval + '\n'

        if None is not self.__escalation:
            config += '  times = {\n'
            config += '    begin = ' + self.__escalation[0] + '\n'
            config += '    end = ' + self.__escalation[1] + '\n'
            config += '  }\n'

        config += ValueMapper.parse_var('command',
                                        self.__command,
                                        value_prefix='command_service_')
        config += ValueMapper.parse_var('period',
                                        self.__time_period,
                                        value_prefix='time_period_')
        config += ValueMapper.parse_var('types', self.__service_types)
        config += ValueMapper.parse_var('states', self.__service_states)
        config += '}\n'
        config += self.apply_for_all()

        return config
Example #10
0
    def get_config(self: T) -> str:
        self.validate()

        config = 'template Dependency "dependency_' + self.__id + '" {\n'
        config += ValueMapper.parse_var('parent_host_name',
                                        self.__parent_host_name)
        config += ValueMapper.parse_var('disable_checks',
                                        self.__disable_checks)
        config += ValueMapper.parse_var('disable_notifications',
                                        self.__disable_notifications)
        config += ValueMapper.parse_var('ignore_soft_states',
                                        self.__ignore_soft_states)
        config += ValueMapper.parse_var('period',
                                        self.__period,
                                        value_prefix='time_period_')
        config += ValueMapper.parse_var('states', self.__states)
        config += '}\n'

        return config
Example #11
0
 def get_config(self) -> str:
     config = ValueMapper.parse_var('vars.icinga_script_dir',
                                    self.__icinga_script_dir)
     config += ValueMapper.parse_var('vars.monitoring_script_dir',
                                     self.__monitoring_script_dir)
     return config
 def user_config_function(self, user):
     email_config = []
     for email in user.get_email():
         email_config.append(
             ValueMapper.parse_var('vars.notification_email', email))
     return email_config
    def get_group_config(self: T) -> str:

        return ValueMapper.parse_var('vars.groups',
                                     self.__service_groups,
                                     value_prefix='servicegroup_')
Example #14
0
    def get_config(self: T) -> str:

        config = Nameable.get_config(self)
        config += CustomVars.get_config(self)
        if not self.__is_check:
            config += ValueMapper.parse_var('vars.zone_name', self.__dns_zone)
        elif self.__override_zone:
            config += ValueMapper.parse_var('zone', self.__dns_zone)
        else:
            config += '  zone = host.vars.zone_name\n'

        if not self.__is_check:
            config += ValueMapper.parse_var('vars.endpoint_name', self.__command_endpoint)
        elif self.__override_endpoint:
            config += ValueMapper.parse_var('command_endpoint', self.__command_endpoint)
        else:
            config += '  command_endpoint = host.vars.endpoint_name\n'

        config += '  check_interval = ' + self.__check_interval + '\n'
        config += '  retry_interval = ' + self.__retry_interval + '\n'
        config += ValueMapper.parse_var('max_check_attempts', self.__max_check_attempts)
        config += ValueMapper.parse_var('enable_perfdata', self.__enable_perfdata)
        config += ValueMapper.parse_var('check_timeout', self.__check_timeout)
        config += ValueMapper.parse_var('vars.notification', self.__notifications, value_prefix='notification_')
        config += ValueMapper.parse_var('vars.downtime', self.__downtimes, value_prefix='downtime_')
        config += ValueMapper.parse_var('vars.dependencies', self.__dependencies, value_prefix='dependency_')
        if self.__use_negation:
            config += ValueMapper.parse_var('vars.negation_ok_status', self.__negation_ok_status)
            config += ValueMapper.parse_var('vars.negation_warning_status', self.__negation_warning_status)
            config += ValueMapper.parse_var('vars.negation_critical_status', self.__negation_critical_status)
            config += ValueMapper.parse_var('vars.negation_unknown_status', self.__negation_unknown_status)
            config += ValueMapper.parse_var('vars.negation_substitute', self.__negation_substitute)
            config += ValueMapper.parse_var('vars.negation_timeout', self.__negation_timeout)

        return config
Example #15
0
    def get_config(self) -> str:
        config = ValueMapper.parse_var('vars.email_addresses', self.__email)
        config += ValueMapper.parse_var('pager', self.__pager)
        config += ValueMapper.parse_var('vars.phone', self.__phone)

        return config
 def get_config(self) -> str:
     return ValueMapper.parse_var('display_name', self.__display_name)