Beispiel #1
0
    def set_interval(self):
        """
        Set interval from config

        """

        interval = int(get_app_config('Alignak-App', 'synthesis_interval'))

        if bool(interval) and interval > 0:
            logger.debug('Dashboard will be updated in %ss', str(interval))
            interval *= 1000
        else:  # pragma: no cover - not testable
            logger.error(
                '"synthesis_interval" option must be greater than 0. Replace by default: 30s'
            )
            interval = 30000

        self.interval = interval
Beispiel #2
0
    def display_dashboard(self):
        """
        Update dashboard and display it

        """

        # Retrieve duration
        duration = int(get_app_config('Dashboard', 'duration'))
        duration *= 1000
        logger.debug('Dashboard Duration : %s', str(duration))

        # Display dashboard...
        self.app_widget.show()
        logger.info('Display dashboard...')

        # ...until the end of the term
        self.timer.timeout.connect(self.app_widget.close)
        self.timer.setSingleShot(True)
        self.timer.start(duration)
Beispiel #3
0
    def mouseMoveEvent(self, event):  # pragma: no cover - not testable
        """ QWidget.mousePressEvent(QMouseEvent) """

        sticky = False

        if 'Dashboard' in self.windowTitle():
            sticky = bool(get_app_config('Dashboard', 'sticky', boolean=True))

        if not sticky:
            try:
                x = event.globalX()
                y = event.globalY()
                x_w = self.offset.x()
                y_w = self.offset.y()
                self.move(x - x_w, y - y_w)
            except AttributeError as e:
                logger.warning('Move Event %s: %s', self.objectName(), str(e))
        else:
            pass
Beispiel #4
0
    def set_position(self):
        """
        Get screen, and return position choosen in settings.

        """

        # Get position choosed by user
        pos = get_app_config('Dashboard', 'position')
        points = pos.split(':')
        screen = QApplication.desktop().screenNumber(
            QApplication.desktop().cursor().pos())

        # Move dashboard dashboard
        if 'top' in points and 'right' in points:
            top_right = QApplication.desktop().screenGeometry(
                screen).topRight()
            self.app_widget.move(top_right.x() - self.width(), top_right.y())
            log_msg = '[top:right] ' + str(top_right)
        elif 'top' in points and 'left' in points:  # pragma: no cover - not fully testable
            top_left = QApplication.desktop().screenGeometry(screen).topLeft()
            self.app_widget.move(top_left)
            log_msg = '[top:left] ' + str(top_left)
        elif 'bottom' in points and 'right' in points:  # pragma: no cover - not fully testable
            bottom_right = QApplication.desktop().screenGeometry(
                screen).bottomRight()
            self.app_widget.move(bottom_right.x() - self.width(),
                                 bottom_right.y() - self.height())
            log_msg = '[bottom:right] ' + str(bottom_right)
        elif 'bottom' in points and 'left' in points:  # pragma: no cover - not fully testable
            bottom_left = QApplication.desktop().screenGeometry(
                screen).bottomLeft()
            self.app_widget.move(bottom_left.x(),
                                 bottom_left.y() - self.height())
            log_msg = '[top:right] ' + str(bottom_left)
        else:  # pragma: no cover - not fully testable
            center = QApplication.desktop().screenGeometry(screen).center()
            self.app_widget.move(center.x() - (self.width() / 2),
                                 center.y() - (self.height() / 2))
            log_msg = '[center] ' + str(center)

        logger.debug('Dashboard Position %s', log_msg)
Beispiel #5
0
    def create_status(self, app_backend):
        """
        Create grid layout for status QWidget

        """

        self.app_backend = app_backend

        # Add Layout
        layout = QGridLayout()
        self.setLayout(layout)

        self.create_daemons_labels(layout)

        # Default text and color
        self.info.setText('All daemons are alive.')
        self.info.setStyleSheet('color: #27ae60;')

        # Update status for first start
        self.check_status()

        # Start checks
        daemon_interval = int(get_app_config('Alignak-App', 'daemon_interval'))
        if bool(daemon_interval) and daemon_interval > 0:
            logger.debug('Alignak Daemons will be checked in %ss',
                         str(daemon_interval))
            daemon_interval *= 1000
        else:
            logger.error(
                '"daemon_interval" option must be greater than 0. Replace by default: 60s'
            )
            daemon_interval = 60000
        timer = QTimer(self)
        timer.start(daemon_interval)
        timer.timeout.connect(self.check_status)

        # Use AppQWidget
        self.app_widget.initialize('Alignak Status')
        self.app_widget.add_widget(self)
        self.app_widget.setMinimumSize(400, 400)
Beispiel #6
0
    def initialize(self, service):
        """
        Inititialize Service QWidget

        :param service: service data
        :type service: dict
        """

        layout = QGridLayout()
        self.setLayout(layout)

        layout.addWidget(self.get_service_icon(service['ls_state']), 0, 0, 2,
                         1)

        if service['display_name'] != '':
            service_name = service['display_name']
        elif service['alias'] != '':
            service_name = service['alias']
        else:
            service_name = service['name']

        # Service name
        service_label = QLabel()
        if get_app_config('Alignak', 'webui'):
            service_label.setText(
                '<h3><a href="%s" style="color: black; text-decoration: none">%s</a></h3>'
                % (get_app_config('Alignak', 'webui') + '/service/' +
                   service['_id'], service_name))
        else:
            service_label.setText('<h3>%s</h3>' % service_name)
        service_label.setTextInteractionFlags(Qt.TextBrowserInteraction)
        service_label.setOpenExternalLinks(True)
        service_label.setToolTip('Service is %s. See in WebUI ?' %
                                 service['ls_state'])
        service_label.setObjectName(service['ls_state'])
        service_label.setMinimumWidth(200)
        service_label.setWordWrap(True)
        layout.addWidget(service_label, 0, 1, 2, 1)
        layout.setAlignment(service_label, Qt.AlignLeft)

        # Buttons
        self.acknowledge_btn = QPushButton()
        self.acknowledge_btn.setIcon(
            QIcon(get_image_path('services_acknowledge')))
        self.acknowledge_btn.setFixedSize(25, 25)
        self.acknowledge_btn.setToolTip('Acknowledge this service')
        layout.addWidget(self.acknowledge_btn, 0, 2, 1, 1)

        self.downtime_btn = QPushButton()
        self.downtime_btn.setIcon(QIcon(get_image_path('services_downtime')))
        self.downtime_btn.setFixedSize(25, 25)
        self.downtime_btn.setToolTip('Schedule a downtime for this service')
        layout.addWidget(self.downtime_btn, 1, 2, 1, 1)

        # Last check
        since_last_check = get_diff_since_last_check(
            service['ls_last_state_changed'])
        diff_last_check = get_diff_since_last_check(service['ls_last_check'])

        last_check = QLabel('<b>Since:</b> %s, <b>Last check:</b> %s' %
                            (since_last_check, diff_last_check))
        layout.addWidget(last_check, 0, 3, 1, 2)

        # Output
        date_output = get_date_from_timestamp(service['ls_last_check'])
        output = QTextEdit('<b>Output:</b> [%s] %s' %
                           (date_output, service['ls_output']))
        output.setObjectName('output')
        output.setToolTip(service['ls_output'])
        output.setTextInteractionFlags(Qt.TextSelectableByMouse)
        output.setFont(QFont('Times', 13))
        layout.addWidget(output, 1, 3, 2, 4)

        # Service details
        business_impact = self.get_stars_widget(int(
            service['business_impact']))
        layout.addWidget(business_impact, 2, 0, 1, 2)
        layout.setAlignment(business_impact, Qt.AlignLeft)

        self.add_services_details(service, layout)
Beispiel #7
0
    def handle_server(self):
        """
        Handle for server button

        """

        server_dialog = QDialog()
        server_dialog.setWindowTitle('Server Configuration')
        server_dialog.setWindowFlags(Qt.FramelessWindowHint)
        server_dialog.setStyleSheet(get_css())
        server_dialog.setFixedSize(300, 300)

        main_layout = QVBoxLayout(server_dialog)
        main_layout.setContentsMargins(0, 0, 0, 0)
        main_layout.addWidget(self.get_logo_widget(server_dialog))

        server_widget = QWidget(self)
        server_widget.setObjectName('login')
        server_layout = QGridLayout(server_widget)

        # Description
        desc_label = QLabel(
            '<h3>Alignak Backend</h3><p>Here you can define alignak settings.</p>'
            '<b>Be sure to enter a valid address</b>')
        desc_label.setWordWrap(True)
        server_layout.addWidget(desc_label, 0, 0, 1, 3)

        # Server URL
        server_layout.addWidget(QLabel('Server'), 1, 0, 1, 1)

        server_url = QLineEdit()
        server_url.setPlaceholderText('alignak backend url')
        server_url.setText(get_app_config('Alignak', 'url'))
        server_layout.addWidget(server_url, 1, 1, 1, 2)

        # Server Port
        server_layout.addWidget(QLabel('Port'), 2, 0, 1, 1)

        server_port = QLineEdit()
        server_port.setPlaceholderText('alignak backend port')
        cur_port = get_app_config('Alignak', 'backend').split(':')[2]
        server_port.setText(cur_port)
        server_layout.addWidget(server_port, 2, 1, 1, 2)

        # Server Processes
        server_layout.addWidget(QLabel('Processes'), 3, 0, 1, 1)

        server_proc = QLineEdit()
        if 'win32' in sys.platform:
            server_proc.setEnabled(False)
        server_proc.setPlaceholderText('alignak backend processes')
        cur_proc = get_app_config('Alignak', 'processes')
        server_proc.setText(cur_proc)
        server_layout.addWidget(server_proc, 3, 1, 1, 2)

        # Valid Button
        valid_btn = QPushButton('Valid')
        valid_btn.clicked.connect(server_dialog.accept)
        server_layout.addWidget(valid_btn, 4, 0, 1, 3)

        main_layout.addWidget(server_widget)

        self.center(server_widget)

        if server_dialog.exec_() == QDialog.Accepted:
            backend_url = '%(url)s:' + str(server_port.text()).rstrip()
            set_app_config('Alignak', 'backend', backend_url)
            set_app_config('Alignak', 'url', str(server_url.text()).rstrip())
            set_app_config('Alignak', 'processes',
                           str(server_proc.text()).rstrip())
    def get_host_widget(self, backend_data):
        """
        Return QWidget for host

        :param backend_data: data of AppBackend
        :type backend_data: dict
        :return: QWidget with with host data
        :rtype: QWidget
        """

        host_widget = QWidget()
        host_widget.setObjectName('host')
        host_layout = QGridLayout(host_widget)

        overall_state_img = QLabel()
        overall_state_img.setPixmap(
            self.get_real_state_icon(backend_data['services']))
        overall_state_img.setScaledContents(True)
        overall_state_img.setToolTip(
            self.get_real_state_text(backend_data['services']))
        host_layout.addWidget(overall_state_img, 0, 0, 2, 1)
        host_layout.setAlignment(overall_state_img, Qt.AlignCenter)

        # Hostname
        host_name = QLabel()
        if get_app_config('Alignak', 'webui'):
            host_name.setText(
                '<h2><a href="%s" style="color: black;text-decoration: none;">%s</a></h2>'
                % (
                    get_app_config('Alignak', 'webui') + '/host/' +
                    backend_data['host']['name'],
                    backend_data['host']['alias'],
                ))
        else:
            host_name.setText('<h2>%s</h2>' % backend_data['host']['alias'])

        host_name.setTextInteractionFlags(Qt.TextBrowserInteraction)
        host_name.setOpenExternalLinks(True)
        host_name.setObjectName('hostname')
        host_name.setToolTip('Host is %s. See in WebUI ?' %
                             backend_data['host']['ls_state'])
        host_layout.addWidget(host_name, 2, 0, 1, 1)
        host_layout.setAlignment(host_name, Qt.AlignCenter)

        # Real State
        host_real_state = QLabel()
        host_real_state.setPixmap(self.get_host_icon(backend_data['host']))
        host_real_state.setFixedSize(48, 48)
        host_real_state.setScaledContents(True)
        host_real_state.setToolTip(self.get_host_tooltip(backend_data['host']))
        host_layout.addWidget(host_real_state, 3, 0, 1, 1)
        host_layout.setAlignment(host_real_state, Qt.AlignCenter)

        real_state = QLabel('Host real state, excluding services')
        host_layout.addWidget(real_state, 4, 0, 1, 1)
        host_layout.setAlignment(real_state, Qt.AlignCenter)

        # Buttons
        self.create_buttons(host_layout, backend_data)
        self.create_host_details(host_layout, backend_data)

        return host_widget
Beispiel #9
0
    def create_banner(self, banner_type, message):
        """
        Create banner QWidget and its QPropertyAnimation

        :param banner_type: defines type of banner: OK, INFO, WARN, or ALERT
        :type banner_type: str
        :param message: message to display in banner
        :type message: str
        """

        layout = QHBoxLayout()
        layout.setSpacing(0)
        layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(layout)

        event_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        self.setToolTip(event_date)

        if banner_type not in self.banner_type:
            banner_type = 'ERROR'

        self.setStyleSheet(get_css())
        self.setObjectName('banner%s' % banner_type)

        valid_btn = QPushButton()
        valid_btn.setMaximumSize(self.banner_height, self.banner_height)
        valid_btn.setObjectName('banner')
        valid_btn.clicked.connect(self.close_banner)
        valid_btn.setIcon(QIcon(get_image_path(banner_type.lower())))

        layout.addWidget(valid_btn)

        if len(message) > 170:
            message = message[:170] + '...'

        if get_app_config('Banners', 'title', boolean=True):
            banner_qlabel = QLabel('<b>%s</b>: %s' % (banner_type, message))
        else:
            banner_qlabel = QLabel('%s' % message)

        banner_qlabel.setWordWrap(True)
        banner_qlabel.setObjectName('banner')
        layout.addWidget(banner_qlabel)

        # Animation
        banner_duration = int(get_app_config('Banners', 'animation'))
        if banner_duration < 0:
            logger.debug('Banner animation: %sms', str(banner_duration))
            logger.error(
                '"animation" option must be equal or greater than 0. Replace by default: 1000ms'
            )
            banner_duration = 1000
        self.animation.setDuration(banner_duration)

        start_value = QPoint(0, 0)
        self.animation.setStartValue(start_value)

        screen = QApplication.desktop().screenNumber(
            QApplication.desktop().cursor().pos())
        end_position = QApplication.desktop().screenGeometry(screen).topRight()
        end_value = QPoint(end_position.x() - self.width(), end_position.y())
        self.animation.setEndValue(end_value)
Beispiel #10
0
    def create_services_actions(self):
        """
        Create services actions.

        """

        logger.info('Create Service Actions')

        self.services_menu.setTitle('Services (N/A)')

        self.qaction_factory.create('services_ok', 'Services OK, Wait...',
                                    self)

        self.qaction_factory.create('services_warning',
                                    'Services WARNING, Wait...',
                                    self.services_menu)

        self.qaction_factory.create('services_critical',
                                    'Services CRITICAL, Wait...',
                                    self.services_menu)

        self.qaction_factory.create('services_unknown',
                                    'Services UNKNOWN, Wait...',
                                    self.services_menu)

        self.qaction_factory.create('services_unreachable',
                                    'Services UNREACHABLE, Wait...',
                                    self.services_menu)

        self.services_menu.addSeparator()

        self.qaction_factory.create('services_acknowledge',
                                    'Services ACKNOWLEDGE, Wait...',
                                    self.services_menu)

        self.qaction_factory.create('services_downtime',
                                    'Services DOWNTIME, Wait...',
                                    self.services_menu)

        if get_app_config('Alignak', 'webui'):
            self.qaction_factory.get('services_ok').triggered.connect(
                self.open_url)
            self.qaction_factory.get('services_warning').triggered.connect(
                self.open_url)
            self.qaction_factory.get('services_critical').triggered.connect(
                self.open_url)
            self.qaction_factory.get('services_unknown').triggered.connect(
                self.open_url)
            self.qaction_factory.get('services_unreachable').triggered.connect(
                self.open_url)

        # Add services actions to menu
        self.services_menu.addAction(self.qaction_factory.get('services_ok'))
        self.services_menu.addAction(
            self.qaction_factory.get('services_warning'))
        self.services_menu.addAction(
            self.qaction_factory.get('services_critical'))
        self.services_menu.addAction(
            self.qaction_factory.get('services_unknown'))
        self.services_menu.addAction(
            self.qaction_factory.get('services_unreachable'))
        self.services_menu.addAction(
            self.qaction_factory.get('services_acknowledge'))
        self.services_menu.addAction(
            self.qaction_factory.get('services_downtime'))

        self.menu.addMenu(self.services_menu)