# Path: simple_monitor_alert/sma.py
#     class _MetaColor(type):
#     class Color(six.with_metaclass(_MetaColor)):
# class Config(ConfigParser):
# class MonitorResults(object):
# class Results(JSONFile):
# class MonitorsInfo(JSONFile):
# class SMA(object):
# class SMAService(SMA):
#         def __getattr__(self, item):
# def get_var_directory():
#     def __init__(self, file):
#     def get_monitor_observables(self, name):
#     def get_observable(self, monitor_name, observable_name, group_name=None):
#     def __init__(self, monitor_name, monitor_results, sma=None):
#     def get_section(self):
#     def get_results_columns(self, columns=None):
#     def __str__(self):
#     def __init__(self, path, create=True, sma=None):
#     def get_default_observable_result():
#     def update_observable_result(self, observable, fail, notified=False):
#     def get_observable_result(self, observable):
#     def add_alert_to_observable_result(self, observable, alert):
#     def __str__(self):
#     def __repr__(self):
#     def get_monitor(self, monitor, create=True):
#     def set_headers(self, monitor, headers):
#     def set_last_execution(self, monitor):
#     def __init__(self, monitors_dir=None, alerts_dir=None, config_file=None):
#     def evaluate_and_alert(self):
#     def alert_all(self, observables, fail=True):
#     def execute_all(self):
#     def evaluate_all(self):
#     def start(self):
# WAIT_SECONDS = 60
# DEFAULT_VAR_DIRECTORY = os.environ.get('VAR_DIRECTORY', '/var/lib/simple-monitor-alert')
# 
# Path: simple_monitor_alert/utils/files.py
# def create_file(path, content=''):
#     import six
#     if not isinstance(content, six.string_types):
#         content = json.dumps(content)
#     if not os.path.exists(path):
#         with open(path, 'w') as f:
#             f.write(content)
#     return path
# 
# class JSONFile(dict):
#     def __init__(self, path, create=True):
#         super(JSONFile, self).__init__()
#         if create:
#             create_file(path, '{}')
#         self.path = path
#         self.read()
# 
#     def read(self):
#         self.clear()
#         self.update(json.load(open(self.path)))
# 
#     def write(self):
#         json.dump(self, open(self.path, 'w'), sort_keys=True, indent=4, separators=(',', ': '))
# 
#     def clear(self):
#         if sys.version_info >= (3, 3):
#             super().clear()
#         else:
#             for key in self:
#                 del self[key]
# 
# Path: simple_monitor_alert/alerts.py
# class AlertBase(object):
#     def __init__(self, config, section=None):
#         self.config = config
#         self.section = section
#         self.init()
# 
#     def init(self):
#         pass


import os
import datetime
import telebot
import sys
import six
import dateutil
import dateutil.tz
from simple_monitor_alert.sma import get_var_directory, JSONFile
from simple_monitor_alert.utils.files import create_file, JSONFile
    from html import escape
    from cgi import escape
from simple_monitor_alert.alerts import AlertBase



SUPPORT_ALERT_IMPORT = True
DEFAULT_MESSAGE = """\
%(icon)b {hostname} [{level}] Simple-Monitor-Alert
 <strong>{name}</strong>
{extra_info}

Observable: {observable_name}
{condition_status} condition: {condition}
"""


LEVELS = {
    None: b'\xE2\x9C\x85',  # Resolved
    'info': b'\xE2\x84\xB9',
    'warning': b'\xF0\x9F\x94\xB4',
    'average': b'\xE2\x9D\x8C',
    'high': b'\xE2\x9D\x97',
    'disaster': b'\xE2\x80\xBC',
}

class Telegram(AlertBase):
    bot = None
    telegram_cache = None

    def init(self):
        token = self.config.get('token')
        self.bot = telebot.TeleBot(token)

# Path: simple_monitor_alert/sma.py
#     class _MetaColor(type):
#     class Color(six.with_metaclass(_MetaColor)):
# class Config(ConfigParser):
# class MonitorResults(object):
# class Results(JSONFile):
# class MonitorsInfo(JSONFile):
# class SMA(object):
# class SMAService(SMA):
#         def __getattr__(self, item):
# def get_var_directory():
#     def __init__(self, file):
#     def get_monitor_observables(self, name):
#     def get_observable(self, monitor_name, observable_name, group_name=None):
#     def __init__(self, monitor_name, monitor_results, sma=None):
#     def get_section(self):
#     def get_results_columns(self, columns=None):
#     def __str__(self):
#     def __init__(self, path, create=True, sma=None):
#     def get_default_observable_result():
#     def update_observable_result(self, observable, fail, notified=False):
#     def get_observable_result(self, observable):
#     def add_alert_to_observable_result(self, observable, alert):
#     def __str__(self):
#     def __repr__(self):
#     def get_monitor(self, monitor, create=True):
#     def set_headers(self, monitor, headers):
#     def set_last_execution(self, monitor):
#     def __init__(self, monitors_dir=None, alerts_dir=None, config_file=None):
#     def evaluate_and_alert(self):
#     def alert_all(self, observables, fail=True):
#     def execute_all(self):
#     def evaluate_all(self):
#     def start(self):
# WAIT_SECONDS = 60
# DEFAULT_VAR_DIRECTORY = os.environ.get('VAR_DIRECTORY', '/var/lib/simple-monitor-alert')
# 
# Path: simple_monitor_alert/utils/files.py
# def create_file(path, content=''):
#     import six
#     if not isinstance(content, six.string_types):
#         content = json.dumps(content)
#     if not os.path.exists(path):
#         with open(path, 'w') as f:
#             f.write(content)
#     return path
# 
# class JSONFile(dict):
#     def __init__(self, path, create=True):
#         super(JSONFile, self).__init__()
#         if create:
#             create_file(path, '{}')
#         self.path = path
#         self.read()
# 
#     def read(self):
#         self.clear()
#         self.update(json.load(open(self.path)))
# 
#     def write(self):
#         json.dump(self, open(self.path, 'w'), sort_keys=True, indent=4, separators=(',', ': '))
# 
#     def clear(self):
#         if sys.version_info >= (3, 3):
#             super().clear()
#         else:
#             for key in self:
#                 del self[key]
# 
# Path: simple_monitor_alert/alerts.py
# class AlertBase(object):
#     def __init__(self, config, section=None):
#         self.config = config
#         self.section = section
#         self.init()
# 
#     def init(self):
#         pass


# Path: alerts/telegram.py
import os
import datetime
import telebot
import sys
import six
import dateutil
import dateutil.tz
from simple_monitor_alert.sma import get_var_directory, JSONFile
from simple_monitor_alert.utils.files import create_file, JSONFile
    from html import escape
    from cgi import escape
from simple_monitor_alert.alerts import AlertBase




SUPPORT_ALERT_IMPORT = True
DEFAULT_MESSAGE = """\
%(icon)b {hostname} [{level}] Simple-Monitor-Alert
 <strong>{name}</strong>
{extra_info}

Observable: {observable_name}
{condition_status} condition: {condition}
"""


LEVELS = {
    None: b'\xE2\x9C\x85',  # Resolved
    'info': b'\xE2\x84\xB9',
    'warning': b'\xF0\x9F\x94\xB4',
    'average': b'\xE2\x9D\x8C',
    'high': b'\xE2\x9D\x97',
    'disaster': b'\xE2\x80\xBC',
}

class Telegram(AlertBase):
    bot = None
    telegram_cache = None

    def init(self):
        token = self.config.get('token')
        self.bot = telebot.TeleBot(token)

        self.telegram_cache = JSONFile(create_file(os.path.join(get_var_directory(), 'telegram-cache.json'), {