Ejemplo n.º 1
0
        }
        $r['children'] = $kids;
        $result['ous'][] = $r;
    }
    echo json_encode($result);
});
// single-day statelogs for hosts of a single OU
$app->get('/statelogs/:ou/:startUnixTime', function ($ouid, $ctime) {
    $result = array();
    $ou = OU::find_one($ouid);
    foreach ($ou->hosts()->order_by_asc('hostname')->find_many() as $host) {
        $hosts[] = $host->id;
    }
    // find 'previous-day[s]-state' for each host
    foreach ($hosts as $hostid) {
        $record = Statelog::where('host_id', $hostid)->where_lt('state_begin', $ctime)->order_by_desc('state_begin')->limit(1)->find_one();
        if ($record) {
            $result[] = $record->as_array();
        }
    }
    foreach (Statelog::where_gt('state_begin', $ctime)->where_lt('state_begin', $ctime + 86400)->where_in('host_id', $hosts)->find_many() as $record) {
        $result[] = $record->as_array();
    }
    echo json_encode($result);
});
//
//  Non-DB-Model requests
//
// provide URI for ember-data REST adapter, based on this php script's location
$app->get('/rest-config.js', function () use($app) {
    $app->response->header('Content-Type', 'application/javascript;charset=utf-8');