def __init__(self, configuration=None, name=None): SimpleService.__init__(self, configuration=configuration, name=name) self.order = ORDER self.definitions = CHARTS self.log_path = self.configuration.get('log_path') self.regex = dict(tls=r_compile(r'\d{1,3}(?:\.\d{1,3}){3}(?::\d+)? (?P<bytes_in>\d+) (?P<bytes_out>\d+)'), static_key=r_compile(r'TCP/[A-Z]+ (?P<direction>(?:read|write)) bytes,(?P<bytes>\d+)'))
def __init__(self, configuration=None, name=None): SimpleService.__init__(self, configuration=configuration, name=name) self.order = ORDER self.definitions = CHARTS self.log_path = self.configuration.get('log_path') self.regex = dict(tls=r_compile(r'(?:[0-9a-f:]+|(?:\d{1,3}(?:\.\d{1,3}){3}(?::\d+)?)) (?P<bytes_in>\d+) (?P<bytes_out>\d+)'), static_key=r_compile(r'TCP/[A-Z]+ (?P<direction>(?:read|write)) bytes,(?P<bytes>\d+)'))
def __init__(self, configuration=None, name=None): SimpleService.__init__(self, configuration=configuration, name=name) self.order = ORDER self.definitions = CHARTS self.log_path = self.configuration.get('log_path') self.regex_data_inter = r_compile(r'(?<=Since ).*?(?=.ROUTING)') self.regex_data_final = r_compile(r'\d{1,3}(?:\.\d{1,3}){3}[:0-9,. ]*') self.regex_users = r_compile(r'\d{1,3}(?:\.\d{1,3}){3}:\d+') self.regex_traffic = r_compile(r'(?<=(?:,| ))\d+(?=(?:,| ))')
def create_view(self, name, hosts): """Create a view with ``hosts``, skeleton plugin and source patterns.""" PLUGIN_REG = r_compile(self.plugin_pattern) SOURCE_REG = r_compile(self.source_pattern) view_sources = [] for h in hosts: plugins = [ p for p in h.get_plugin_list() if PLUGIN_REG.search(p) ] plugins = h.create_plugins(plugins) for p in plugins: sources = [ s for s in p.get_data_sources() if SOURCE_REG.search(s) ] sources = p.create_data_sources(sources) view_sources.extend(sources) view = View.objects.create(name=name) view.sources.add(*view_sources) return view
def castro_post(): name = request.forms.get('name') username = request.forms.get('username') lastName = request.forms.get('lastName') gender = request.forms.get('gender') password = request.forms.get('passwd') email = request.forms.get('email') fullDate = request.forms.get('age') regex = r_compile(r'\d{2}/\d{2}/\d{4}') if len(password) < 6: msg = 'Senha inválida, use ao menos 6 caracteres' elif '@' not in email: msg = 'Email inválido' elif not regex.findall(fullDate): msg = 'Data inválida' else: msg = ''' Bem vind{} {} <br /> Usuário: {} <br /> Senha: {}'''.format('a' if gender.startswith('f') else 'o', name, username, password) return dict(title='Cadastro', path=msg, css_file='/static/style.css', lista=['cadastro', 'login'])
def __init__(self, configuration=None, name=None): SimpleService.__init__(self, configuration=configuration, name=name) self.regex = r_compile(r'(\d+);(\d+);(\d+)') self.log_path = self.configuration.get('log_path', '/var/log/smartd') self.raw_values = self.configuration.get('raw_values') self.attr = self.configuration.get('smart_attributes', []) self.previous_data = dict()
def create_view(self, name, hosts): """Create a view with ``hosts``, skeleton plugin and source patterns.""" PLUGIN_REG = r_compile(self.plugin_pattern) SOURCE_REG = r_compile(self.source_pattern) view_sources = [] for h in hosts: plugins = [p for p in h.get_plugin_list() if PLUGIN_REG.search(p)] plugins = h.create_plugins(plugins) for p in plugins: sources = [ s for s in p.get_data_sources() if SOURCE_REG.search(s) ] sources = p.create_data_sources(sources) view_sources.extend(sources) view = View.objects.create(name=name) view.sources.add(*view_sources) return view
def __init__(self, configuration=None, name=None): SimpleService.__init__(self, configuration=configuration, name=name) self.regex = r_compile(r'(\d+);(\d+);(\d+)') self.log_path = self.configuration.get('log_path', '/var/log/smartd') self.raw_values = self.configuration.get('raw_values') self.attr = self.configuration.get('smart_attributes', []) self.exclude_disks = self.configuration.get('exclude_disks', str()).split() self.order = list() self.definitions = dict() self.disks = list() for path_to_disk in find_disks_in_log_path(self.log_path): disk_name = os.path.basename(path_to_disk).split('.')[-3] for pattern in self.exclude_disks: if pattern in disk_name: break else: self.disks.append(Disk(name=disk_name, path=path_to_disk))
def test__parse_with_regex(self): from re import compile as r_compile from kamaki.cli.utils import _parse_with_regex for args in product( ( 'this is a line', 'this_is_also_a_line', 'This "text" is quoted', 'This "quoted" "text" is more "complicated"', 'Is this \'quoted\' text "double \'quoted\' or not?"', '"What \'about\' the" oposite?', ' Try with a " single double quote', 'Go "down \'deep " deeper \'bottom \' up" go\' up" !'), ( '\'.*?\'|".*?"|^[\S]*$', r'"([A-Za-z0-9_\./\\-]*)"', r'\"(.+?)\"', '\\^a\\.\\*\\$')): r_parser = r_compile(args[1]) self.assertEqual( _parse_with_regex(*args), (r_parser.split(args[0]), r_parser.findall(args[0])))
# -*- coding: utf-8 -*- # Description: fail2ban log netdata python.d module # Author: l2isbad from re import compile as r_compile from os import access as is_accessible, R_OK from os.path import isdir, getsize from glob import glob import bisect from base import LogService priority = 60000 retries = 60 REGEX_JAILS = r_compile(r'\[([A-Za-z-_0-9]+)][^\[\]]*?(?<!# )enabled = (?:(true|false))') REGEX_DATA = r_compile(r'\[(?P<jail>[A-Za-z-_0-9]+)\] (?P<action>(?:(U|B)))[a-z]+ (?P<ipaddr>\d{1,3}(?:\.\d{1,3}){3})') ORDER = ['jails_bans', 'jails_in_jail'] class Service(LogService): """ fail2ban log class Reads logs line by line Jail auto detection included It produces following charts: * Bans per second for every jail * Banned IPs for every jail (since the last restart of netdata) """ def __init__(self, configuration=None, name=None): LogService.__init__(self, configuration=configuration, name=name) self.order = ORDER self.definitions = dict()
# -*- coding: utf-8 -*- # Description: fail2ban log netdata python.d module # Author: l2isbad from re import compile as r_compile from os import access as is_accessible, R_OK from os.path import isdir, getsize from glob import glob import bisect from base import LogService priority = 60000 retries = 60 REGEX_JAILS = r_compile( r'\[([A-Za-z-_0-9]+)][^\[\]]*?(?<!# )enabled = (?:(true|false))') REGEX_DATA = r_compile( r'\[(?P<jail>[A-Za-z-_0-9]+)\] (?P<action>[A-Z])[a-z]+ (?P<ipaddr>\d{1,3}(?:\.\d{1,3}){3})' ) ORDER = ['jails_bans', 'jails_in_jail'] class Service(LogService): """ fail2ban log class Reads logs line by line Jail auto detection included It produces following charts: * Bans per second for every jail * Banned IPs for every jail (since the last restart of netdata) """ def __init__(self, configuration=None, name=None):
# Description: fail2ban log netdata python.d module # Author: l2isbad import bisect from glob import glob from re import compile as r_compile from os import access as is_accessible, R_OK from os.path import isdir, getsize from bases.FrameworkServices.LogService import LogService priority = 60000 retries = 60 REGEX_JAILS = r_compile(r'\[([a-zA-Z0-9_-]+)\][^\[\]]+?enabled\s+= (true|false)') REGEX_DATA = r_compile(r'\[(?P<jail>[A-Za-z-_0-9]+)\] (?P<action>U|B)[a-z]+ (?P<ipaddr>\d{1,3}(?:\.\d{1,3}){3})') ORDER = ['jails_bans', 'jails_in_jail'] class Service(LogService): """ fail2ban log class Reads logs line by line Jail auto detection included It produces following charts: * Bans per second for every jail * Banned IPs for every jail (since the last restart of netdata) """ def __init__(self, configuration=None, name=None): LogService.__init__(self, configuration=configuration, name=name)
# -*- coding: utf-8 -*- # Description: fail2ban log netdata python.d module # Author: l2isbad from base import LogService from re import compile as r_compile from os import access as is_accessible, R_OK from os.path import isdir from glob import glob import bisect priority = 60000 retries = 60 REGEX_JAILS = r_compile(r'\[([A-Za-z-_]+)][^\[\]]*?(?<!# )enabled = true') REGEX_DATA = r_compile( r'\[(?P<jail>[a-z]+)\] (?P<ban>[A-Z])[a-z]+ (?P<ipaddr>\d{1,3}(?:\.\d{1,3}){3})' ) ORDER = ['jails_bans', 'jails_in_jail'] class Service(LogService): def __init__(self, configuration=None, name=None): LogService.__init__(self, configuration=configuration, name=name) self.order = ORDER self.log_path = self.configuration.get('log_path', '/var/log/fail2ban.log') self.conf_path = self.configuration.get('conf_path', '/etc/fail2ban/jail.local') self.conf_dir = self.configuration.get('conf_dir', '') self.bans = dict() try:
CHARTS = { 'users': { 'options': [None, 'OpenVPN Active Users', 'active users', 'users', 'openvpn_status.users', 'line'], 'lines': [ ['users', None, 'absolute'], ] }, 'traffic': { 'options': [None, 'OpenVPN Traffic', 'KB/s', 'traffic', 'openvpn_status.traffic', 'area'], 'lines': [ ['bytes_in', 'in', 'incremental', 1, 1 << 10], ['bytes_out', 'out', 'incremental', 1, -1 << 10] ] } } TLS_REGEX = r_compile(r'(?:[0-9a-f]+:[0-9a-f:]+|(?:\d{1,3}(?:\.\d{1,3}){3}(?::\d+)?)) (?P<bytes_in>\d+) (?P<bytes_out>\d+)') STATIC_KEY_REGEX = r_compile(r'TCP/[A-Z]+ (?P<direction>(?:read|write)) bytes,(?P<bytes>\d+)') class Service(SimpleService): def __init__(self, configuration=None, name=None): SimpleService.__init__(self, configuration=configuration, name=name) self.order = ORDER self.definitions = CHARTS self.log_path = self.configuration.get('log_path') self.regex = { 'tls': TLS_REGEX, 'static_key': STATIC_KEY_REGEX } def check(self):
# Description: fail2ban log hibenchmarks python.d module # Author: l2isbad # SPDX-License-Identifier: GPL-3.0+ import bisect from glob import glob from re import compile as r_compile from os import access as is_accessible, R_OK from os.path import isdir, getsize from bases.FrameworkServices.LogService import LogService priority = 60000 retries = 60 REGEX_JAILS = r_compile( r'\[([a-zA-Z0-9_-]+)\][^\[\]]+?enabled\s+= (true|false)') REGEX_DATA = r_compile( r'\[(?P<jail>[A-Za-z-_0-9]+)\] (?P<action>U|B)[a-z]+ (?P<ipaddr>\d{1,3}(?:\.\d{1,3}){3})' ) ORDER = ['jails_bans', 'jails_in_jail'] class Service(LogService): """ fail2ban log class Reads logs line by line Jail auto detection included It produces following charts: * Bans per second for every jail * Banned IPs for every jail (since the last restart of hibenchmarks) """
CHARTS = { 'users': { 'options': [None, 'OpenVPN Active Users', 'active users', 'users', 'openvpn_status.users', 'line'], 'lines': [ ['users', None, 'absolute'], ] }, 'traffic': { 'options': [None, 'OpenVPN Traffic', 'KB/s', 'traffic', 'openvpn_status.traffic', 'area'], 'lines': [ ['bytes_in', 'in', 'incremental', 1, 1 << 10], ['bytes_out', 'out', 'incremental', 1, -1 << 10] ] } } TLS_REGEX = r_compile(r'(?:[0-9a-f:]+|(?:\d{1,3}(?:\.\d{1,3}){3}(?::\d+)?)) (?P<bytes_in>\d+) (?P<bytes_out>\d+)') STATIC_KEY_REGEX = r_compile(r'TCP/[A-Z]+ (?P<direction>(?:read|write)) bytes,(?P<bytes>\d+)') class Service(SimpleService): def __init__(self, configuration=None, name=None): SimpleService.__init__(self, configuration=configuration, name=name) self.order = ORDER self.definitions = CHARTS self.log_path = self.configuration.get('log_path') self.regex = { 'tls': TLS_REGEX, 'static_key': STATIC_KEY_REGEX } def check(self):
from sys import argv from re import compile as r_compile from re import MULTILINE, DOTALL from bokeh.charts import Donut from bokeh.embed import components from bokeh.resources import INLINE from pandas import DataFrame as df from pandas import concat # Regex REMOVE_SCENARIOS = r_compile(r"^@scenario.begin(.*?)@scenario.end$", MULTILINE | DOTALL) # --- get scenarios SCENARIOS = r_compile(r"Cen[á|a]rio: .*|Contexto: .*") # --- get steps STEPS = r_compile( r"\s+(E\s|Ent[ã|a]o|Quando|Dad[o|a|as|os]|Mas)(.*?) ... (failed|passed|skipped) in (.*)" ) # --- get data ERRORS = r_compile(r'errors="(\d)"') SKIPPED = r_compile(r'skipped="(\d)"') NAME = r_compile(r'<testcase classname=".*?\.(.*?)"') ERROR_DESC = r_compile(r'CDATA\[(.*)]]>.*</error>', MULTILINE | DOTALL) L_DFS = [] # ----- Lista dos dataframes para compilação FILO = [] # ----- Fila para o html def head(file, tup): """