Exemplo n.º 1
0
def test_alertprofiles_remove_profile(db, client, activated_dummy_profile):
    url = reverse('alertprofiles-profile-remove')
    response = client.post(
        url,
        follow=True,
        data={
            'profile': [activated_dummy_profile.id],
        },
    )
    assert response.status_code == 200
    assert "Confirm deletion" in smart_str(response.content)
    assert activated_dummy_profile.name in smart_str(response.content)
    assert AlertProfile.objects.filter(
        pk=activated_dummy_profile.pk).count() == 1
Exemplo n.º 2
0
def test_alertprofiles_activate_profile(db, client, dummy_profile):
    # remarkably, activation/deactivation of profiles belong in the remove view!
    url = reverse('alertprofiles-profile-remove')
    response = client.post(
        url,
        follow=True,
        data={
            'activate': dummy_profile.id,
        },
    )
    assert response.status_code == 200
    assert "Active profile set" in smart_str(response.content)
    assert dummy_profile.name in smart_str(response.content)
    preference = AlertPreference.objects.get(account=dummy_profile.account)
    assert preference.active_profile == dummy_profile
Exemplo n.º 3
0
def backoffaction(error, retrylimitaction):
    """Perform an action if the retry limit has been reached."""

    global failed
    queue = nav.smsd.navdbqueue.NAVDBQueue()
    msgs = queue.getmsgs('N')

    if retrylimitaction == "ignore":
        # Queued messages are marked as ignored, logs a critical error with
        # message details, then resumes run.
        numbmsg = queue.cancel()
        error_message = (
            u"Dispatch retry limit has been reached. Dispatching SMS has failed %s "
            u"times. Ignoring %s message(s)."
        ) % (failed, numbmsg)

        for index, msg in enumerate(msgs):
            error_message += u'\n%s: "%s" --> %s' % (
                index + 1,
                smart_str(msg['msg']),
                smart_str(msg['name']),
            )

        error_message += u"\nError message: %s" % error
        _logger.critical(error_message)
        failed = 0
        resetdelay()

    elif retrylimitaction == "shutdown":
        # Logs the number of unsent messages and time of the oldest in queue
        # before shutting down daemon.
        _logger.critical(
            "Dispatch retry limit has been reached. Dispatching SMS has failed %d "
            "times. %d unsent message(s), the oldest from %s. "
            "\nError message: %s "
            "\nShutting down daemon.\n",
            failed,
            len(msgs),
            msgs[0]["time"],
            error,
        )
        sys.exit(0)

    else:
        _logger.warning(
            "No retry limit action is set or the configured option is not valid."
        )
Exemplo n.º 4
0
def test_alertprofiles_deactivate_profile(db, client, activated_dummy_profile):
    # remarkably, activation/deactivation of profiles belong in the remove view!
    url = reverse('alertprofiles-profile-remove')
    response = client.post(
        url,
        follow=True,
        data={
            'deactivate': activated_dummy_profile.id,
        },
    )
    assert response.status_code == 200
    print(type(response.content))
    assert "was deactivated" in smart_str(response.content)
    assert activated_dummy_profile.name in smart_str(response.content)
    preference = AlertPreference.objects.get(
        account=activated_dummy_profile.account)
    assert preference.active_profile is None
Exemplo n.º 5
0
def test_port_search_should_match_case_insensitively(client, netbox):
    ifc = netbox.interface_set.all()[0]
    url = reverse(
        'ipdevinfo-interface-details-by-name',
        kwargs={
            'netbox_sysname': netbox.sysname,
            'port_name': ifc.ifdescr.upper(),
        },
    )
    response = client.get(url)
    assert response.status_code == 200
    assert ifc.ifdescr in smart_str(response.content)
Exemplo n.º 6
0
 def _get_cpu_names(self, indexes):
     if not indexes:
         defer.returnValue({})
     self._logger.debug("getting cpu names from ENTITY-MIB")
     base_oid = EntityMib.nodes['entPhysicalName'].oid
     oids = [str(base_oid + (index, )) for index in indexes]
     names = yield self.agent_proxy.get(oids)
     self._logger.debug("cpu name result: %r", names)
     names = {
         OID(oid)[-1]: smart_str(value)
         for oid, value in names.items() if value
     }
     defer.returnValue(names)
Exemplo n.º 7
0
def test_alertprofiles_save_profile(db, client):
    url = reverse('alertprofiles-profile-save')
    profile_name = 'Catch 22'

    response = client.post(
        url,
        follow=True,
        data={
            'name': profile_name,
            'daily_dispatch_time': '08:00',
            'weekly_dispatch_time': '08:00',
            'weekly_dispatch_day': AlertProfile.MONDAY,
        },
    )

    assert response.status_code == 200
    print(response.content)
    assert "Saved profile" in smart_str(response.content)
    assert AlertProfile.objects.filter(name=profile_name).count() > 0
Exemplo n.º 8
0
 def _make_result_dict(self,
                       sensor_oid,
                       base_oid,
                       serial,
                       desc,
                       u_o_m=None,
                       **kwargs):
     """Make a simple dictionary to return to plugin"""
     if not sensor_oid or not base_oid or not serial or not desc:
         return {}
     oid = OID(base_oid) + OID(sensor_oid)
     internal_name = smart_str(serial) + desc
     res = {
         'oid': oid,
         'unit_of_measurement': u_o_m,
         'description': desc,
         'internal_name': internal_name,
         'mib': self.get_module_name(),
     }
     res.update(kwargs)
     return res
Exemplo n.º 9
0
def test_alertprofiles_view(client, view):
    """Simple GET tests for various non-modifying alertprofiles views"""
    url = reverse(view)
    response = client.get(url)
    assert "admin" in smart_str(response.content)
Exemplo n.º 10
0
def test_bad_name_should_not_crash_ipdevinfo(client, badname):
    """Tests "bad" device names to ensure they dont crash ipdevinfo lookup views"""
    url = reverse("ipdevinfo-details-by-name", kwargs={"name": badname})
    response = client.get(url)
    assert response.status_code == 200
    assert badname in smart_str(response.content)
Exemplo n.º 11
0
def test_device_details_should_include_sysname(client, netbox):
    url = reverse('ipdevinfo-details-by-name', args=(netbox.sysname, ))
    response = client.get(url)
    assert netbox.sysname in smart_str(response.content)