Example #1
0
def ping_all(request):
    '''
    Ping all devices
    '''

    devices = Device.objects.all().order_by('name')
    for dev in devices :
        hf = Karma()
        try:
          isUp=ping(dev.name)
        except Exception as e :
            hf.save(dev, 0, 1)
        else:
            hf.save(dev, 0, not isUp)
    return redirect(index)
Example #2
0
def device_ping(request, device_id):
    '''
    Ping and display a device
    '''

    error_message = None
    dev = get_object_or_404(Device, pk=device_id)
    hf = Karma()
    try:
      isUp=ping(dev.name)
    except Exception as e :
        error_message = e.__unicode__()
        hf.save(dev, 0, 1)
    else:
        hf.save(dev, 0, not isUp)
    return redirect(device, device_id)
Example #3
0
                hf.save(device, 3, 0, options.message)
    elif options.wol :
        if (device.wakeup == False) :
            logging.error("This device don't allow the wake up.")
        else:
            print("Booting with mac address : %s" % device.MAC)
            try:
                wake_on_lan(device.MAC)
            except Exception as e:
                logging.error("Exception %s" % e)
                hf.save(device, 1, 1)
            else:
                hf.save(device, 1, 0)
    elif options.history :
        record = History.objects.filter(device=device).latest('timestamp')
        print("%s %s @ %s -> %s " %
              (ACTION_TYPES_CHOICES[record.action][1], record.device.name,
               str(record.timestamp)[:19], RESULTS_CODE[record.result][1]))
    else:
        try:
            isUp = ping(device.name)
        except Exception as e:
            logging.error("Exception %s" % e)
            hf.save(device, 0, 1)
        else:
            hf.save(device, 0, not isUp)
        if isUp :
            print("Device %s is up." % device.name)
        else :
            print("Device %s is down." % device.name)