from random import SystemRandom
from bases.FrameworkServices.SimpleService import SimpleService

priority = 90000

ORDER = [
    'app-servers',
    'app-times',
    'classifiers'
]

CHARTS = {
    'app-servers': {
        # 'options': [name, title, units, family, context, charttype]
        'options': [None, 'App Server Page Loads', None, None, 'context', 'stacked'], # line indicates that it is a line graph
        'lines': [
            ['app servers total'] #must be a valid key in 'get_data()'s return 
        ]
    },
    'app-times': {
        'options': [None, 'NewsBlur App Times', None, None, 'context', 'stacked'], # line indicates that it is a line graph
        'lines': [
            ['app times total']
        ]
    },
    'classifiers': {
        'options': [None, 'Classifiers', None, None, 'context', 'stacked'], # line indicates that it is a line graph
        'lines': [
            ['classifiers feeds']
        ]
    }
}


class Service(SimpleService):
    def __init__(self, configuration=None, name=None):
        SimpleService.__init__(self, configuration=configuration, name=name)
        self.order = ORDER
        self.definitions = CHARTS
        self.random = SystemRandom()
        self.num_lines = 1
        self.lower = self.configuration.get('lower', 0)
        self.upper = self.configuration.get('upper', 100)

    @staticmethod
    def check():
        return True

    def get_data(self):

        data = dict()
        charts = {
            "app-servers": "app servers total",
            "app-times": "app times total",
            "classifiers": "classifiers feeds"
        }
        for chart, dimension_id in charts.items():

            if dimension_id not in self.charts[chart]:
                self.charts[chart].add_dimension([dimension_id])

            data[dimension_id] = self.random.randint(self.lower, self.upper)
        return data
@@ -89,16 +89,1142 @@
 Service%0A
+import os%0Aimport requests%0A%0Aclass Monitor():%0A        %0A    MONITOR_URL = os.getenv(%22MONITOR_URL%22)%0A    if MONITOR_URL == %22https://haproxy:443/monitor%22:%0A        verify = False%0A    else:%0A        verify = False%0A%0A    def __init__(self):%0A%0A        endpoints = %7B%0A            %22app_servers%22: %22/app-servers%22,%0A            %22app_times%22: %22/app-times%22,%0A            %22classifiers%22: %22/classifiers%22,%0A            %22db_times%22: %22/db-times%22,%0A            %22errors%22: %22/errors%22,%0A            %22feed_counts%22: %22/feed-counts%22,%0A            %22feeds%22: %22/feeds%22,%0A            %22load_times%22: %22/load-times%22,%0A            %22stories%22: %22/stories%22,%0A            %22task_codes%22: %22/task-codes%22,%0A            %22task_pipeline%22: %22/task-pipeline%22,%0A            %22task_servers%22: %22/task-servers%22,%0A            %22task_times%22: %22/task-times%22,%0A            %22updates%22: %22/updates%22,%0A            %22users%22: %22/users%22,%0A        %7D%0A%0A        for name, endpoint in endpoints.items():%0A            setattr(self, name, self.call_monitor(endpoint))%0A%0A    def call_monitor(self, endpoint):%0A        uri = self.MONITOR_URL + endpoint%0A        res = requests.get(uri, verify=self.verify)%0A        return res.json()%0A        
 %0Apriorit
@@ -2345,134 +2345,26 @@
 elf.
-num_lines = 1%0A        self.lower = self.configuration.get('lower', 0)%0A        self.upper = self.configuration.get('upper', 100
+monitor = Monitor(
 )%0A%0A 
@@ -2863,30 +2863,14 @@
 int(
-self.lower, self.upper
+0, 100
 )%0A  

add Monitor class to newsblur chart to make it easier to retrieve data