示例#1
0
    def test_get_services(self):
        res = utils.get_services()

        self.assertIn('data', res.json())
        self.assertIsInstance(res.json()['data'], list)
        self.assert_response_time(res, 3)
        self.assertEqual(res.status_code, 200)
        for data in res.json()['data']:
            self.__class__.valid_service_ids.append(data['id'])
            self.attributes_checker(data['attributes'])
示例#2
0
def dashboard(request):

    # Get statistics
    c = adagios.status.utils.get_statistics(request)

    c['messages'] = []
    c['errors'] = []

    all_down_hosts = utils.get_hosts(request, state__isnot='0', **request.GET)
    hostnames_that_are_down = map(lambda x: x.get('name'), all_down_hosts)
    # Discover network outages,

    # Remove acknowledgements and also all hosts where all parent hosts are down
    c['host_problems'] = []  # Unhandled host problems
    c['network_problems'] = []  # Network outages
    for i in all_down_hosts:
        if i.get('acknowledged') != 0:
            continue
        if i.get('scheduled_downtime_depth') != 0:
            continue

        # Do nothing if parent of this host is also down
        for parent in i.get('parents'):
            if parent in hostnames_that_are_down:
                parent_is_down = True
                continue
        else:
            parent_is_down = False

        if parent_is_down == True:
            continue

        # If host has network childs, put them in the network outages box
        if i.get('childs') == []:
            c['host_problems'].append(i)
        else:
            c['network_problems'].append(i)
    #
    c['hosts'] = c['network_problems'] + c['host_problems']
    # Service problems
    c['service_problems'] = utils.get_services(request,
                                               state__isnot="0",
                                               acknowledged="0",
                                               scheduled_downtime_depth="0",
                                               host_state="0",
                                               **request.GET)
    # Sort problems by state and last_check as secondary sort field
    c['service_problems'].sort(
        reverse=True, cmp=lambda a, b: cmp(a['last_check'], b['last_check']))
    c['service_problems'].sort(reverse=True,
                               cmp=lambda a, b: cmp(a['state'], b['state']))
    return render_to_response('status_dashboard.html',
                              c,
                              context_instance=RequestContext(request))
示例#3
0
def services(request):
    """ This view handles list of services  """
    c = {}
    c['messages'] = []
    c['errors'] = []
    fields = [
        'host_name', 'description', 'plugin_output', 'last_check',
        'host_state', 'state', 'last_state_change', 'acknowledged',
        'downtimes', 'host_downtimes', 'comments_with_info'
    ]
    c['services'] = utils.get_services(request, fields=fields, **request.GET)
    return render_to_response('status_services.html',
                              c,
                              context_instance=RequestContext(request))
示例#4
0
 def search(self, text, extractor, *args, **kwargs):
     extractors = get_services()
     for i in extractors:
         if extractor == i.interface.name:
             self.extractor = i.interface()
             break
     log.debug("Started search for {0} (selected extractor: {1})".format(text, self.extractor.name))
     wx.CallAfter(self.window.list.Clear)
     self.extractor.search(text)
     self.results = self.extractor.results
     for i in self.results:
         wx.CallAfter(self.window.list.Append, i.format_track())
     if len(self.results) == 0:
         wx.CallAfter(self.change_status, _(u"No results found. "))
     else:
         wx.CallAfter(self.change_status, u"")
         wx.CallAfter(self.window.list.SetFocus)
def index():

    if request.method == 'POST':
        form = request.form

        service_ids = [int(v) for k, v in form.items() if k[:7] == ('service')]
        services = [session['services'][i] for i in service_ids]

        now = int(time())
        fifo_queue = open(FIFO_QUEUE, 'w')

        # Parse duration from the form
        duration = form.get('duration', None)

        # If duration has been specified
        if duration:

            time_format = '%d-%m-%Y %H:%M'
            end_time = datetime.strptime(form['duration'], time_format)
            end_time_timestamp = int(end_time.timestamp())

            dates = {
                'start_time': now,
                'duration': end_time_timestamp - now,
                'end_time': end_time_timestamp,
            }

            for service in services:
                data = ChainMap(service, form, dates)
                fifo_queue.write(downtime_string.format(**data))

        else:
            for service in services:
                data = ChainMap(service, {'time': now}, form)
                fifo_queue.write(acknowledge_string.format(**data))

        fifo_queue.close()
        flash('Request processed!')
        return redirect(url_for('index'))

    # Fetch the nagios services and store in session
    services = get_services(NAGIOS_DAT_FILE)
    session['services'] = services

    return render_template('index.html', services=services)
示例#6
0
 def create_config(self):
     self.output_devices = player.player.get_output_devices()
     self.view.create_general(
         output_devices=[i for i in self.output_devices])
     current_output_device = config.app["main"]["output_device"]
     for i in self.output_devices:
         # here we must compare against the str version of the vlc's device identifier.
         if i == current_output_device:
             self.view.set_value("general", "output_device", i)
             break
     self.view.realize()
     extractors = get_services(import_all=True)
     for i in extractors:
         if hasattr(i, "settings"):
             panel = getattr(i, "settings")(self.view.notebook)
             self.view.notebook.InsertSubPage(1, panel, panel.name)
             panel.load()
             if hasattr(panel, "on_enabled"):
                 panel.on_enabled()
示例#7
0
 def __init__(self):
     super(Controller, self).__init__()
     log.debug("Starting main controller...")
     # Setting up the player object
     player.setup()
     # Get main window
     self.window = mainWindow.mainWindow(extractors=[i.interface.name for i in get_services()])
     log.debug("Main window created")
     self.window.change_status(_(u"Ready"))
     # Here we will save results for searches as song objects.
     self.results = []
     self.connect_events()
     self.timer = wx.Timer(self.window)
     self.window.Bind(wx.EVT_TIMER, self.on_timer, self.timer)
     self.timer.Start(75)
     self.window.vol_slider.SetValue(player.player.volume)
     # Shows window.
     utils.call_threaded(updater.do_update)
     log.debug("Music DL is ready")
     self.window.Show()
示例#8
0
 def reload_extractors(self):
     extractors = [i.interface.name for i in get_services()]
     self.window.extractor.SetItems(extractors)
     self.window.extractor.SetValue(extractors[0])
示例#9
0
import pytest
import utils

@pytest.mark.parametrize("name", utils.get_services())
@pytest.mark.parametrize("host", utils.get_host())
def test_services(host, name):
    service = host.service(name)
    assert service.is_running
示例#10
0
def get_endpoints():
  results = { "endpoints": utils.get_services(options) }
  return flask.jsonify(**results)
示例#11
0
#!/usr/bin/env python
import utils
import os
import sys

services_list = utils.get_services()
def control_all():
    for service in services_list:
        os.system(" ".join(["./daemon_action.py",sys.argv[1],service]))

if __name__ == "__main__":
    control_all()