<commit_before>#!/usr/bin/python

# -*- coding: utf-8 -*-

# Copyright (C) 2009-2012:
# <NAME>, <EMAIL>
# <NAME>, <EMAIL>
# <NAME>, <EMAIL>
# <NAME>, <EMAIL>
#
# This file is part of Shinken.
#
# Shinken is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Shinken is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Shinken.  If not, see <http://www.gnu.org/licenses/>.

"""
This class is for linking the WebUI with Graphite,
for mainly get graphs and links.
"""

import re
import socket

from .graphite_utils import GraphStyle, GraphiteMetric
from .util import GraphFactory
from shinken.log import logger
from shinken.basemodule import BaseModule
from shinken.misc.perfdata import PerfDatas


properties = {
    'daemons': ['webui'],
    'type': 'graphite_webui'
}


# called by the plugin manager
def get_instance(plugin):
    logger.info("[Graphite UI] Get a graphite UI data module for plugin %s" % plugin.get_name())

    instance = Graphite_Webui(plugin)
    return instance


class Graphite_Webui(BaseModule):
    def __init__(self, modconf):
        BaseModule.__init__(self, modconf)
        self._uri = ''
        self.app = None

        # service name to use for host check
        self.hostcheck = getattr(modconf, 'hostcheck', '__HOST__')

        # load styles
        self.styles = dict(default=GraphStyle())
        self._load_styles(modconf)

        self.uri = getattr(modconf, 'uri', '')
        logger.info("[Graphite UI] Configuration - uri: %s", self.uri)

        self.rewrite_rules = getattr(modconf, 'rewrite_rule', '')
        for r in self.rewrite_rules:
            try:
                rule, sub = r.split('=', 1)
            except ValueError:
                logger.warning('Unable to split "%s" into a rule an a substitution'.r)
                logger.warning('Expected rule in format "rule=substitution"')
                continue<commit_msg>stupid oversight<commit_after>#!/usr/bin/python

# -*- coding: utf-8 -*-

# Copyright (C) 2009-2012:
# <NAME>, <EMAIL>
# <NAME>, <EMAIL>
# <NAME>, <EMAIL>
# <NAME>, <EMAIL>
#
# This file is part of Shinken.
#
# Shinken is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Shinken is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Shinken.  If not, see <http://www.gnu.org/licenses/>.

"""
This class is for linking the WebUI with Graphite,
for mainly get graphs and links.
"""

import re
import socket

from .graphite_utils import GraphStyle, GraphiteMetric
from .util import GraphFactory
from shinken.log import logger
from shinken.basemodule import BaseModule
from shinken.misc.perfdata import PerfDatas


properties = {
    'daemons': ['webui'],
    'type': 'graphite_webui'
}


# called by the plugin manager
def get_instance(plugin):
    logger.info("[Graphite UI] Get a graphite UI data module for plugin %s" % plugin.get_name())

    instance = Graphite_Webui(plugin)
    return instance


class Graphite_Webui(BaseModule):
    def __init__(self, modconf):
        BaseModule.__init__(self, modconf)
        self._uri = ''
        self.app = None

        # service name to use for host check
        self.hostcheck = getattr(modconf, 'hostcheck', '__HOST__')

        # load styles
        self.styles = dict(default=GraphStyle())
        self._load_styles(modconf)

        self.uri = getattr(modconf, 'uri', '')
        logger.info("[Graphite UI] Configuration - uri: %s", self.uri)

        self.rewrite_rules = getattr(modconf, 'graphite_rewrite_rule', '')
        for r in self.rewrite_rules:
            try:
                rule, sub = r.split('=', 1)
            except ValueError:
                logger.warning('Unable to split "%s" into a rule an a substitution'.r)
                logger.warning('Expected rule in format "rule=substitution"')
                continue
{'fraction_non_alphanumeric': 0.10059676044330776, 'fraction_numerical': 0.004688832054560955, 'mean_word_length': 3.1239015817223197, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2707999', 'n_tokens_mistral': 1407, 'n_tokens_neox': 1355, 'n_words': 504}