Пример #1
0
 public function getDataFor($metric, $startTime, $endTime)
 {
     // when are we looking for?
     $humanStartTime = date('Y-m-d H:i:s', $startTime);
     $humanEndTime = date('Y-m-d H:i:s', $endTime);
     // what are we doing?
     $log = usingLog()->startAction("get raw data from graphite for '{$metric}' between '{$humanStartTime}' and '{$humanEndTime}'");
     // find out where graphite is
     $graphiteUrl = fromConfig()->getModuleSetting('graphite.url');
     if (substr($graphiteUrl, -1, 1) !== '/') {
         $graphiteUrl .= '/';
     }
     // get the requested data
     $response = fromHttp()->get("{$graphiteUrl}render?format=json&target={$metric}&from={$startTime}&until={$endTime}");
     // are there any stats in the response?
     assertsArray($response->chunks)->isExpectedType();
     assertsArray($response->chunks)->isNotEmpty();
     // assemble the raw chunks into one string to decode
     $rawStats = implode("", $response->chunks);
     assertsString($rawStats)->isValidJson();
     $stats = json_decode($rawStats);
     // all done
     $log->endAction();
     return $stats;
 }
<?php

// ========================================================================
//
// STORY DETAILS
//
// ------------------------------------------------------------------------
$story = newStoryFor('Storyplayer')->inGroup('Modules')->called('HTTP: Can connect to self-signed SSL server');
$story->requiresStoryplayerVersion(2);
// ========================================================================
//
// POSSIBLE ACTION(S)
//
// ------------------------------------------------------------------------
$story->addAction(function () {
    foreach (hostWithRole('ssl_target') as $hostname) {
        $url = "https://" . fromHost($hostname)->getHostname();
        fromHttp()->get($url);
    }
});
// ========================================================================
//
// POST-TEST INSPECTION
//
// ------------------------------------------------------------------------
$story->addPostTestInspection(function ($st) {
    // do nothing
});
Пример #3
0
 public function stopMonitoring()
 {
     // what are we doing?
     $log = usingLog()->startAction("tell SavageD on host '{$this->args[0]}' to stop sending stats to statsd");
     // where are we doing this?
     $url = $this->getSavagedUrl() . "/stats/monitoring";
     // make the request
     usingHttp()->post($url, array("monitoring" => false));
     // did it work?
     $response = fromHttp()->get($url);
     expectsHttpResponse($response)->hasStatusCode(200);
     expectsHttpResponse($response)->hasBody('{"monitoring":false}');
     // all done
     $log->endAction();
 }