示例#1
0
 public function execute($filterChain)
 {
     // execute this filter only once
     if ($this->isFirstCall()) {
         $user = sfContext::getInstance()->getUser();
         if (!$user->isAuthenticated()) {
             $cookie = $this->getContext()->getRequest()->getCookie('rayku');
             if ($cookie) {
                 $value = unserialize(base64_decode($cookie));
                 $c = new Criteria();
                 $c->add(UserPeer::COOKIE_KEY, $value[0]);
                 $c->add(UserPeer::USERNAME, $value[1]);
                 $raykuUser = UserPeer::doSelectOne($c);
                 if ($raykuUser instanceof User) {
                     // sign in
                     StatsD::increment("login.remember_me_success");
                     $user->signIn($raykuUser);
                 } else {
                     StatsD::increment("login.remember_me_failure");
                 }
             }
         }
     }
     // Execute next filter
     $filterChain->execute();
 }
示例#2
0
    /**
     * Updates one or more stats counters by arbitrary amounts.
     *
     * @param string|array $stats The metric(s) to update. Should be either a string or array of metrics.
     * @param int|1 $delta The amount to increment/decrement each metric by.
     * @param float|1 $sampleRate the rate (0-1) for sampling.
     * @return boolean
     **/
    public static function updateStats($stats, $delta=1, $sampleRate=1) {
        if (!is_array($stats)) { $stats = array($stats); }
        $data = array();
        foreach($stats as $stat) {
            $data[$stat] = "$delta|c";
        }

        StatsD::send($data, $sampleRate);
    }
示例#3
0
文件: Db.php 项目: karbowiak/seriis
 /**
  * @param string $query
  * @param array $parameters
  * @param int $duration
  */
 public function logQuery($query, $parameters = array(), $duration = 0)
 {
     $this->statsd->increment('website_queryCount');
     // Don't log queries taking less than 10 seconds.
     if ($duration < 10000) {
         return;
     }
     $baseAddr = '';
     foreach ($parameters as $k => $v) {
         $query = str_replace($k, "'" . $v . "'", $query);
     }
     $uri = isset($_SERVER['REQUEST_URI']) ? "Query page: https://{$baseAddr}" . $_SERVER['REQUEST_URI'] . "\n" : '';
     $this->app->Logging->log('INFO', ($duration != 0 ? number_format($duration / 1000, 3) . 's ' : '') . " Query: \n{$query};\n{$uri}");
 }
示例#4
0
 public function login()
 {
     $this->assign('columns', Table::factory('Users')->getColumns());
     if ($this->request->isPost()) {
         $user = Table::factory('Users')->login($this->request->getVar('email'), $this->request->getVar('password'));
         if ($user) {
             $user->addToSession();
             StatsD::increment("login.success");
             return $this->redirectAction("index");
         }
         // tut tut
         StatsD::increment("login.failure");
         Log::warn("Invalid admin login attempt from IP [" . $this->request->getIp() . "] for email [" . $this->request->getVar('email') . "]");
         $this->addError('Invalid login details');
     }
 }
示例#5
0
function process_port_etherlike(&$this_port, $device)
{
    // Used to loop below for StatsD
    $etherlike_oids = array('dot3StatsAlignmentErrors', 'dot3StatsFCSErrors', 'dot3StatsSingleCollisionFrames', 'dot3StatsMultipleCollisionFrames', 'dot3StatsSQETestErrors', 'dot3StatsDeferredTransmissions', 'dot3StatsLateCollisions', 'dot3StatsExcessiveCollisions', 'dot3StatsInternalMacTransmitErrors', 'dot3StatsCarrierSenseErrors', 'dot3StatsFrameTooLongs', 'dot3StatsInternalMacReceiveErrors', 'dot3StatsSymbolErrors');
    // Overwrite ifDuplex with dot3StatsDuplexStatus if it exists
    if (isset($this_port['dot3StatsDuplexStatus'])) {
        // echo("dot3Duplex, ");
        $this_port['ifDuplex'] = $this_port['dot3StatsDuplexStatus'];
    }
    if ($this_port['ifType'] == "ethernetCsmacd" && isset($this_port['dot3StatsIndex'])) {
        // Check to make sure Port data is cached.
        rrdtool_update_ng($device, 'port-dot3', array('dot3StatsAlignmentErrors' => $this_port['dot3StatsAlignmentErrors'], 'dot3StatsFCSErrors' => $this_port['dot3StatsFCSErrors'], 'dot3StatsSingleCollisionFrames' => $this_port['dot3StatsSingleCollisionFrames'], 'dot3StatsMultipleCollisionFrames' => $this_port['dot3StatsMultipleCollisionFrames'], 'dot3StatsSQETestErrors' => $this_port['dot3StatsSQETestErrors'], 'dot3StatsDeferredTransmissions' => $this_port['dot3StatsDeferredTransmissions'], 'dot3StatsLateCollisions' => $this_port['dot3StatsLateCollisions'], 'dot3StatsExcessiveCollisions' => $this_port['dot3StatsExcessiveCollisions'], 'dot3StatsInternalMacTransmitErrors' => $this_port['dot3StatsInternalMacTransmitErrors'], 'dot3StatsCarrierSenseErrors' => $this_port['dot3StatsCarrierSenseErrors'], 'dot3StatsFrameTooLongs' => $this_port['dot3StatsFrameTooLongs'], 'dot3StatsInternalMacReceiveErrors' => $this_port['dot3StatsInternalMacReceiveErrors'], 'dot3StatsSymbolErrors' => $this_port['dot3StatsSymbolErrors']), get_port_rrdindex($this_port));
        if ($GLOBALS['config']['statsd']['enable'] == TRUE) {
            foreach ($etherlike_oids as $oid) {
                // Update StatsD/Carbon
                StatsD::gauge(str_replace(".", "_", $device['hostname']) . '.' . 'port' . '.' . $this_port['ifIndex'] . '.' . $oid, $this_port[$oid]);
            }
        }
    }
}
示例#6
0
function process_port_adsl(&$this_port, $device, $port)
{
    // Check to make sure Port data is cached.
    if (!isset($this_port['adslLineCoding'])) {
        return;
    }
    // Used below for StatsD only
    $adsl_oids = array('adslAtucCurrSnrMgn', 'adslAtucCurrAtn', 'adslAtucCurrOutputPwr', 'adslAtucCurrAttainableRate', 'adslAtucChanCurrTxRate', 'adslAturCurrSnrMgn', 'adslAturCurrAtn', 'adslAturCurrOutputPwr', 'adslAturCurrAttainableRate', 'adslAturChanCurrTxRate', 'adslAtucPerfLofs', 'adslAtucPerfLoss', 'adslAtucPerfLprs', 'adslAtucPerfESs', 'adslAtucPerfInits', 'adslAturPerfLofs', 'adslAturPerfLoss', 'adslAturPerfLprs', 'adslAturPerfESs', 'adslAtucChanCorrectedBlks', 'adslAtucChanUncorrectBlks', 'adslAturChanCorrectedBlks', 'adslAturChanUncorrectBlks');
    $adsl_db_oids = array('adslLineCoding', 'adslLineType', 'adslAtucInvVendorID', 'adslAtucInvVersionNumber', 'adslAtucCurrSnrMgn', 'adslAtucCurrAtn', 'adslAtucCurrOutputPwr', 'adslAtucCurrAttainableRate', 'adslAturInvSerialNumber', 'adslAturInvVendorID', 'adslAturInvVersionNumber', 'adslAtucChanCurrTxRate', 'adslAturChanCurrTxRate', 'adslAturCurrSnrMgn', 'adslAturCurrAtn', 'adslAturCurrOutputPwr', 'adslAturCurrAttainableRate');
    $adsl_tenth_oids = array('adslAtucCurrSnrMgn', 'adslAtucCurrAtn', 'adslAtucCurrOutputPwr', 'adslAturCurrSnrMgn', 'adslAturCurrAtn', 'adslAturCurrOutputPwr');
    foreach ($adsl_tenth_oids as $oid) {
        if (isset($this_port[$oid])) {
            $this_port[$oid] = $this_port[$oid] / 10;
        }
    }
    if (dbFetchCell("SELECT COUNT(*) FROM `ports_adsl` WHERE `port_id` = ?", array($port['port_id'])) == "0") {
        dbInsert(array('port_id' => $port['port_id']), 'ports_adsl');
    }
    $adsl_update = array('port_adsl_updated' => array('NOW()'));
    foreach ($adsl_db_oids as $oid) {
        $adsl_update[$oid] = $this_port[$oid];
    }
    dbUpdate($adsl_update, 'ports_adsl', '`port_id` = ?', array($port['port_id']));
    if ($this_port['adslAtucCurrSnrMgn'] > "1280") {
        $this_port['adslAtucCurrSnrMgn'] = "U";
    }
    if ($this_port['adslAturCurrSnrMgn'] > "1280") {
        $this_port['adslAturCurrSnrMgn'] = "U";
    }
    rrdtool_update_ng($device, 'port-adsl', array('AtucCurrSnrMgn' => $this_port['adslAtucCurrSnrMgn'], 'AtucCurrAtn' => $this_port['adslAtucCurrAtn'], 'AtucCurrOutputPwr' => $this_port['adslAtucCurrOutputPwr'], 'AtucCurrAttainableR' => $this_port['adslAtucCurrAttainableR'], 'AtucChanCurrTxRate' => $this_port['adslAtucChanCurrTxRate'], 'AturCurrSnrMgn' => $this_port['adslAturCurrSnrMgn'], 'AturCurrAtn' => $this_port['adslAturCurrAtn'], 'AturCurrOutputPwr' => $this_port['adslAturCurrOutputPwr'], 'AturCurrAttainableR' => $this_port['adslAturCurrAttainableR'], 'AturChanCurrTxRate' => $this_port['adslAturChanCurrTxRate'], 'AtucPerfLofs' => $this_port['adslAtucPerfLofs'], 'AtucPerfLoss' => $this_port['adslAtucPerfLoss'], 'AtucPerfLprs' => $this_port['adslAtucPerfLprs'], 'AtucPerfESs' => $this_port['adslAtucPerfESs'], 'AtucPerfInits' => $this_port['adslAtucPerfInits'], 'AturPerfLofs' => $this_port['adslAturPerfLofs'], 'AturPerfLoss' => $this_port['adslAturPerfLoss'], 'AturPerfLprs' => $this_port['adslAturPerfLprs'], 'AturPerfESs' => $this_port['adslAturPerfESs'], 'AtucChanCorrectedBl' => $this_port['adslAtucChanCorrectedBl'], 'AtucChanUncorrectBl' => $this_port['adslAtucChanUncorrectBl'], 'AturChanCorrectedBl' => $this_port['adslAturChanCorrectedBl'], 'AturChanUncorrectBl' => $this_port['adslAturChanUncorrectBl']), get_port_rrdindex($port));
    if ($GLOBALS['config']['statsd']['enable']) {
        foreach ($adsl_oids as $oid) {
            // Update StatsD/Carbon
            StatsD::gauge(str_replace(".", "_", $device['hostname']) . '.' . 'port' . '.' . $port['ifIndex'] . '.' . $oid, $this_port[$oid]);
        }
    }
    //echo("ADSL (".$this_port['adslLineCoding']."/".formatRates($this_port['adslAtucChanCurrTxRate'])."/".formatRates($this_port['adslAturChanCurrTxRate']).")");
}
示例#7
0
 /**
  * Converts a Zotero_Item object to a SimpleXMLElement Atom object
  *
  * Note: Increment Z_CONFIG::$CACHE_VERSION_ATOM_ENTRY when changing
  * the response.
  *
  * @param	object				$item		Zotero_Item object
  * @param	string				$content
  * @return	SimpleXMLElement					Item data as SimpleXML element
  */
 public static function convertItemToAtom(Zotero_Item $item, $queryParams, $permissions, $sharedData = null)
 {
     $t = microtime(true);
     // Uncached stuff or parts of the cache key
     $version = $item->version;
     $parent = $item->getSource();
     $isRegularItem = !$parent && $item->isRegularItem();
     $downloadDetails = $permissions->canAccess($item->libraryID, 'files') ? Zotero_Storage::getDownloadDetails($item) : false;
     if ($isRegularItem) {
         $numChildren = $permissions->canAccess($item->libraryID, 'notes') ? $item->numChildren() : $item->numAttachments();
     }
     // <id> changes based on group visibility in v1
     if ($queryParams['v'] < 2) {
         $id = Zotero_URI::getItemURI($item, false, true);
     } else {
         $id = Zotero_URI::getItemURI($item);
     }
     $libraryType = Zotero_Libraries::getType($item->libraryID);
     // Any query parameters that have an effect on the output
     // need to be added here
     $allowedParams = array('content', 'style', 'css', 'linkwrap');
     $cachedParams = Z_Array::filterKeys($queryParams, $allowedParams);
     $cacheVersion = 2;
     $cacheKey = "atomEntry_" . $item->libraryID . "/" . $item->id . "_" . md5($version . json_encode($cachedParams) . ($downloadDetails ? 'hasFile' : '') . ($libraryType == 'group' ? 'id' . $id : '')) . "_" . $queryParams['v'] . "_" . $cacheVersion . (isset(Z_CONFIG::$CACHE_VERSION_ATOM_ENTRY) ? "_" . Z_CONFIG::$CACHE_VERSION_ATOM_ENTRY : "") . (in_array('bib', $queryParams['content']) && isset(Z_CONFIG::$CACHE_VERSION_BIB) ? "_" . Z_CONFIG::$CACHE_VERSION_BIB : "");
     $xmlstr = Z_Core::$MC->get($cacheKey);
     if ($xmlstr) {
         try {
             // TEMP: Strip control characters
             $xmlstr = Zotero_Utilities::cleanString($xmlstr, true);
             $doc = new DOMDocument();
             $doc->loadXML($xmlstr);
             $xpath = new DOMXpath($doc);
             $xpath->registerNamespace('atom', Zotero_Atom::$nsAtom);
             $xpath->registerNamespace('zapi', Zotero_Atom::$nsZoteroAPI);
             $xpath->registerNamespace('xhtml', Zotero_Atom::$nsXHTML);
             // Make sure numChildren reflects the current permissions
             if ($isRegularItem) {
                 $xpath->query('/atom:entry/zapi:numChildren')->item(0)->nodeValue = $numChildren;
             }
             // To prevent PHP from messing with namespace declarations,
             // we have to extract, remove, and then add back <content>
             // subelements. Otherwise the subelements become, say,
             // <default:span xmlns="http://www.w3.org/1999/xhtml"> instead
             // of just <span xmlns="http://www.w3.org/1999/xhtml">, and
             // xmlns:default="http://www.w3.org/1999/xhtml" gets added to
             // the parent <entry>. While you might reasonably think that
             //
             // echo $xml->saveXML();
             //
             // and
             //
             // $xml = new SimpleXMLElement($xml->saveXML());
             // echo $xml->saveXML();
             //
             // would be identical, you would be wrong.
             $multiFormat = !!$xpath->query('/atom:entry/atom:content/zapi:subcontent')->length;
             $contentNodes = array();
             if ($multiFormat) {
                 $contentNodes = $xpath->query('/atom:entry/atom:content/zapi:subcontent');
             } else {
                 $contentNodes = $xpath->query('/atom:entry/atom:content');
             }
             foreach ($contentNodes as $contentNode) {
                 $contentParts = array();
                 while ($contentNode->hasChildNodes()) {
                     $contentParts[] = $doc->saveXML($contentNode->firstChild);
                     $contentNode->removeChild($contentNode->firstChild);
                 }
                 foreach ($contentParts as $part) {
                     if (!trim($part)) {
                         continue;
                     }
                     // Strip the namespace and add it back via SimpleXMLElement,
                     // which keeps it from being changed later
                     if (preg_match('%^<[^>]+xmlns="http://www.w3.org/1999/xhtml"%', $part)) {
                         $part = preg_replace('%^(<[^>]+)xmlns="http://www.w3.org/1999/xhtml"%', '$1', $part);
                         $html = new SimpleXMLElement($part);
                         $html['xmlns'] = "http://www.w3.org/1999/xhtml";
                         $subNode = dom_import_simplexml($html);
                         $importedNode = $doc->importNode($subNode, true);
                         $contentNode->appendChild($importedNode);
                     } else {
                         if (preg_match('%^<[^>]+xmlns="http://zotero.org/ns/transfer"%', $part)) {
                             $part = preg_replace('%^(<[^>]+)xmlns="http://zotero.org/ns/transfer"%', '$1', $part);
                             $html = new SimpleXMLElement($part);
                             $html['xmlns'] = "http://zotero.org/ns/transfer";
                             $subNode = dom_import_simplexml($html);
                             $importedNode = $doc->importNode($subNode, true);
                             $contentNode->appendChild($importedNode);
                         } else {
                             $docFrag = $doc->createDocumentFragment();
                             $docFrag->appendXML($part);
                             $contentNode->appendChild($docFrag);
                         }
                     }
                 }
             }
             $xml = simplexml_import_dom($doc);
             StatsD::timing("api.items.itemToAtom.cached", (microtime(true) - $t) * 1000);
             StatsD::increment("memcached.items.itemToAtom.hit");
             // Skip the cache every 10 times for now, to ensure cache sanity
             if (Z_Core::probability(10)) {
                 $xmlstr = $xml->saveXML();
             } else {
                 return $xml;
             }
         } catch (Exception $e) {
             error_log($xmlstr);
             error_log("WARNING: " . $e);
         }
     }
     $content = $queryParams['content'];
     $contentIsHTML = sizeOf($content) == 1 && $content[0] == 'html';
     $contentParamString = urlencode(implode(',', $content));
     $style = $queryParams['style'];
     $entry = '<?xml version="1.0" encoding="UTF-8"?>' . '<entry xmlns="' . Zotero_Atom::$nsAtom . '" xmlns:zapi="' . Zotero_Atom::$nsZoteroAPI . '"/>';
     $xml = new SimpleXMLElement($entry);
     $title = $item->getDisplayTitle(true);
     $title = $title ? $title : '[Untitled]';
     $xml->title = $title;
     $author = $xml->addChild('author');
     $createdByUserID = null;
     $lastModifiedByUserID = null;
     switch (Zotero_Libraries::getType($item->libraryID)) {
         case 'group':
             $createdByUserID = $item->createdByUserID;
             // Used for zapi:lastModifiedByUser below
             $lastModifiedByUserID = $item->lastModifiedByUserID;
             break;
     }
     if ($createdByUserID) {
         $author->name = Zotero_Users::getUsername($createdByUserID);
         $author->uri = Zotero_URI::getUserURI($createdByUserID);
     } else {
         $author->name = Zotero_Libraries::getName($item->libraryID);
         $author->uri = Zotero_URI::getLibraryURI($item->libraryID);
     }
     $xml->id = $id;
     $xml->published = Zotero_Date::sqlToISO8601($item->dateAdded);
     $xml->updated = Zotero_Date::sqlToISO8601($item->dateModified);
     $link = $xml->addChild("link");
     $link['rel'] = "self";
     $link['type'] = "application/atom+xml";
     $href = Zotero_API::getItemURI($item);
     if (!$contentIsHTML) {
         $href .= "?content={$contentParamString}";
     }
     $link['href'] = $href;
     if ($parent) {
         // TODO: handle group items?
         $parentItem = Zotero_Items::get($item->libraryID, $parent);
         $link = $xml->addChild("link");
         $link['rel'] = "up";
         $link['type'] = "application/atom+xml";
         $href = Zotero_API::getItemURI($parentItem);
         if (!$contentIsHTML) {
             $href .= "?content={$contentParamString}";
         }
         $link['href'] = $href;
     }
     $link = $xml->addChild('link');
     $link['rel'] = 'alternate';
     $link['type'] = 'text/html';
     $link['href'] = Zotero_URI::getItemURI($item, true);
     // If appropriate permissions and the file is stored in ZFS, get file request link
     if ($downloadDetails) {
         $details = $downloadDetails;
         $link = $xml->addChild('link');
         $link['rel'] = 'enclosure';
         $type = $item->attachmentMIMEType;
         if ($type) {
             $link['type'] = $type;
         }
         $link['href'] = $details['url'];
         if (!empty($details['filename'])) {
             $link['title'] = $details['filename'];
         }
         if (isset($details['size'])) {
             $link['length'] = $details['size'];
         }
     }
     $xml->addChild('zapi:key', $item->key, Zotero_Atom::$nsZoteroAPI);
     $xml->addChild('zapi:version', $item->version, Zotero_Atom::$nsZoteroAPI);
     if ($lastModifiedByUserID) {
         $xml->addChild('zapi:lastModifiedByUser', Zotero_Users::getUsername($lastModifiedByUserID), Zotero_Atom::$nsZoteroAPI);
     }
     $xml->addChild('zapi:itemType', Zotero_ItemTypes::getName($item->itemTypeID), Zotero_Atom::$nsZoteroAPI);
     if ($isRegularItem) {
         $val = $item->creatorSummary;
         if ($val !== '') {
             $xml->addChild('zapi:creatorSummary', htmlspecialchars($val), Zotero_Atom::$nsZoteroAPI);
         }
         $val = $item->getField('date', true, true, true);
         if ($val !== '') {
             if ($queryParams['v'] < 3) {
                 $val = substr($val, 0, 4);
                 if ($val !== '0000') {
                     $xml->addChild('zapi:year', $val, Zotero_Atom::$nsZoteroAPI);
                 }
             } else {
                 $sqlDate = Zotero_Date::multipartToSQL($val);
                 if (substr($sqlDate, 0, 4) !== '0000') {
                     $xml->addChild('zapi:parsedDate', Zotero_Date::sqlToISO8601($sqlDate), Zotero_Atom::$nsZoteroAPI);
                 }
             }
         }
         $xml->addChild('zapi:numChildren', $numChildren, Zotero_Atom::$nsZoteroAPI);
     }
     if ($queryParams['v'] < 3) {
         $xml->addChild('zapi:numTags', $item->numTags(), Zotero_Atom::$nsZoteroAPI);
     }
     $xml->content = '';
     //
     // DOM XML from here on out
     //
     $contentNode = dom_import_simplexml($xml->content);
     $domDoc = $contentNode->ownerDocument;
     $multiFormat = sizeOf($content) > 1;
     // Create a root XML document for multi-format responses
     if ($multiFormat) {
         $contentNode->setAttribute('type', 'application/xml');
         /*$multicontent = $domDoc->createElementNS(
         			Zotero_Atom::$nsZoteroAPI, 'multicontent'
         		);
         		$contentNode->appendChild($multicontent);*/
     }
     foreach ($content as $type) {
         // Set the target to either the main <content>
         // or a <multicontent> <content>
         if (!$multiFormat) {
             $target = $contentNode;
         } else {
             $target = $domDoc->createElementNS(Zotero_Atom::$nsZoteroAPI, 'subcontent');
             $contentNode->appendChild($target);
         }
         $target->setAttributeNS(Zotero_Atom::$nsZoteroAPI, "zapi:type", $type);
         if ($type == 'html') {
             if (!$multiFormat) {
                 $target->setAttribute('type', 'xhtml');
             }
             $div = $domDoc->createElementNS(Zotero_Atom::$nsXHTML, 'div');
             $target->appendChild($div);
             $html = $item->toHTML(true);
             $subNode = dom_import_simplexml($html);
             $importedNode = $domDoc->importNode($subNode, true);
             $div->appendChild($importedNode);
         } else {
             if ($type == 'citation') {
                 if (!$multiFormat) {
                     $target->setAttribute('type', 'xhtml');
                 }
                 if (isset($sharedData[$type][$item->libraryID . "/" . $item->key])) {
                     $html = $sharedData[$type][$item->libraryID . "/" . $item->key];
                 } else {
                     if ($sharedData !== null) {
                         //error_log("Citation not found in sharedData -- retrieving individually");
                     }
                     $html = Zotero_Cite::getCitationFromCiteServer($item, $queryParams);
                 }
                 $html = new SimpleXMLElement($html);
                 $html['xmlns'] = Zotero_Atom::$nsXHTML;
                 $subNode = dom_import_simplexml($html);
                 $importedNode = $domDoc->importNode($subNode, true);
                 $target->appendChild($importedNode);
             } else {
                 if ($type == 'bib') {
                     if (!$multiFormat) {
                         $target->setAttribute('type', 'xhtml');
                     }
                     if (isset($sharedData[$type][$item->libraryID . "/" . $item->key])) {
                         $html = $sharedData[$type][$item->libraryID . "/" . $item->key];
                     } else {
                         if ($sharedData !== null) {
                             //error_log("Bibliography not found in sharedData -- retrieving individually");
                         }
                         $html = Zotero_Cite::getBibliographyFromCitationServer(array($item), $queryParams);
                     }
                     $html = new SimpleXMLElement($html);
                     $html['xmlns'] = Zotero_Atom::$nsXHTML;
                     $subNode = dom_import_simplexml($html);
                     $importedNode = $domDoc->importNode($subNode, true);
                     $target->appendChild($importedNode);
                 } else {
                     if ($type == 'json') {
                         if ($queryParams['v'] < 2) {
                             $target->setAttributeNS(Zotero_Atom::$nsZoteroAPI, "zapi:etag", $item->etag);
                         }
                         $textNode = $domDoc->createTextNode($item->toJSON(false, $queryParams, true));
                         $target->appendChild($textNode);
                     } else {
                         if ($type == 'csljson') {
                             $arr = $item->toCSLItem();
                             $json = Zotero_Utilities::formatJSON($arr);
                             $textNode = $domDoc->createTextNode($json);
                             $target->appendChild($textNode);
                         } else {
                             if (in_array($type, Zotero_Translate::$exportFormats)) {
                                 $export = Zotero_Translate::doExport(array($item), $type);
                                 $target->setAttribute('type', $export['mimeType']);
                                 // Insert XML into document
                                 if (preg_match('/\\+xml$/', $export['mimeType'])) {
                                     // Strip prolog
                                     $body = preg_replace('/^<\\?xml.+\\n/', "", $export['body']);
                                     $subNode = $domDoc->createDocumentFragment();
                                     $subNode->appendXML($body);
                                     $target->appendChild($subNode);
                                 } else {
                                     $textNode = $domDoc->createTextNode($export['body']);
                                     $target->appendChild($textNode);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // TEMP
     if ($xmlstr) {
         $uncached = $xml->saveXML();
         if ($xmlstr != $uncached) {
             $uncached = str_replace('<zapi:year></zapi:year>', '<zapi:year/>', $uncached);
             $uncached = str_replace('<content zapi:type="none"></content>', '<content zapi:type="none"/>', $uncached);
             $uncached = str_replace('<zapi:subcontent zapi:type="coins" type="text/html"></zapi:subcontent>', '<zapi:subcontent zapi:type="coins" type="text/html"/>', $uncached);
             $uncached = str_replace('<title></title>', '<title/>', $uncached);
             $uncached = str_replace('<note></note>', '<note/>', $uncached);
             $uncached = str_replace('<path></path>', '<path/>', $uncached);
             $uncached = str_replace('<td></td>', '<td/>', $uncached);
             if ($xmlstr != $uncached) {
                 error_log("Cached Atom item entry does not match");
                 error_log("  Cached: " . $xmlstr);
                 error_log("Uncached: " . $uncached);
                 Z_Core::$MC->set($cacheKey, $uncached, 3600);
                 // 1 hour for now
             }
         }
     } else {
         $xmlstr = $xml->saveXML();
         Z_Core::$MC->set($cacheKey, $xmlstr, 3600);
         // 1 hour for now
         StatsD::timing("api.items.itemToAtom.uncached", (microtime(true) - $t) * 1000);
         StatsD::increment("memcached.items.itemToAtom.miss");
     }
     return $xml;
 }
if ($port_stats[$port['ifIndex']] && $port['ifType'] == "ethernetCsmacd" && isset($port_stats[$port['ifIndex']]['dot3StatsIndex'])) {
    // Check to make sure Port data is cached.
    $this_port =& $port_stats[$port['ifIndex']];
    // TODO: remove $old_rrdfile?
    $old_rrdfile = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("etherlike-" . $port['ifIndex'] . ".rrd");
    $rrdfile = get_port_rrdfilename($device, $port, "dot3");
    if (!file_exists($rrdfile)) {
        if (file_exists($old_rrdfile)) {
            rename($old_rrdfile, $rrd_file);
        } else {
            foreach ($etherlike_oids as $oid) {
                $oid = truncate(str_replace("dot3Stats", "", $oid), 19, '');
                $rrd_create .= " DS:{$oid}:COUNTER:600:U:100000000000";
            }
            rrdtool_create($rrdfile, $rrd_create);
        }
    }
    if ($config['statsd']['enable'] == TRUE) {
        foreach ($etherlike_oids as $oid) {
            // Update StatsD/Carbon
            StatsD::gauge(str_replace(".", "_", $device['hostname']) . '.' . 'port' . '.' . $port['ifIndex'] . '.' . $oid, $this_port[$oid]);
        }
    }
    $rrdupdate = "N";
    foreach ($etherlike_oids as $oid) {
        $data = $this_port[$oid] + 0;
        $rrdupdate .= ":{$data}";
    }
    rrdtool_update($rrdfile, $rrdupdate);
    echo "EtherLike ";
}
示例#9
0
 public static function deleteByLibrary($libraryID)
 {
     Zotero_DB::beginTransaction();
     // Delete from MySQL
     self::deleteByLibraryMySQL($libraryID);
     // Delete from Elasticsearch
     $type = self::getWriteType();
     $libraryQuery = new \Elastica\Query\Term();
     $libraryQuery->setTerm("libraryID", $libraryID);
     $query = new \Elastica\Query($libraryQuery);
     $start = microtime(true);
     $response = $type->deleteByQuery($query);
     StatsD::timing("elasticsearch.client.item_fulltext.delete_library", (microtime(true) - $start) * 1000);
     if ($response->hasError()) {
         throw new Exception($response->getError());
     }
     Zotero_DB::commit();
 }
示例#10
0
                $peer['c_update']['PrefixAdminLimit'] = $cbgpPeerPrefixAdminLimit;
                $peer['c_update']['PrefixThreshold'] = $cbgpPeerPrefixThreshold;
                $peer['c_update']['PrefixClearThreshold'] = $cbgpPeerPrefixClearThreshold;
                $peer['c_update']['AdvertisedPrefixes'] = $cbgpPeerAdvertisedPrefixes;
                $peer['c_update']['SuppressedPrefixes'] = $cbgpPeerSuppressedPrefixes;
                $peer['c_update']['WithdrawnPrefixes'] = $cbgpPeerWithdrawnPrefixes;
                if (dbFetchCell('SELECT COUNT(cbgp_id) FROM `bgpPeers_cbgp-state` WHERE `cbgp_id` = ?', array($peer_afi['cbgp_id'])) == 0) {
                    dbInsert(array('cbgp_id' => $peer_afi['cbgp_id']), 'bgpPeers_cbgp-state');
                }
                dbUpdate($peer['c_update'], 'bgpPeers_cbgp-state', '`cbgp_id` = ?', array($peer_afi['cbgp_id']));
                // Update cbgp StatsD
                if ($config['statsd']['enable'] == TRUE) {
                    foreach (array('AcceptedPrefixes', 'DeniedPrefixes', 'AdvertisedPrefixes', 'SuppressedPrefixes', 'WithdrawnPrefixes') as $oid) {
                        // Update StatsD/Carbon
                        $r_oid = 'cbgpPeer' . $oid;
                        StatsD::gauge(str_replace(".", "_", $device['hostname']) . '.' . 'bgp' . '.' . str_replace(".", "_", $peer_ip) . ".{$afi}.{$safi}" . '.' . $oid, ${$r_oid});
                    }
                }
                // Update cbgp RRD
                $cbgp_rrd = "cbgp-{$peer_ip}.{$afi}.{$safi}.rrd";
                $rrd_create = "DS:AcceptedPrefixes:GAUGE:600:U:100000000000 \\\n           DS:DeniedPrefixes:GAUGE:600:U:100000000000 \\\n           DS:AdvertisedPrefixes:GAUGE:600:U:100000000000 \\\n           DS:SuppressedPrefixes:GAUGE:600:U:100000000000 \\\n           DS:WithdrawnPrefixes:GAUGE:600:U:100000000000 ";
                rrdtool_create($device, $cbgp_rrd, $rrd_create);
                rrdtool_update($device, $cbgp_rrd, "N:{$cbgpPeerAcceptedPrefixes}:{$cbgpPeerDeniedPrefixes}:{$cbgpPeerAdvertisedPrefixes}:{$cbgpPeerSuppressedPrefixes}:{$cbgpPeerWithdrawnPrefixes}");
            }
            # while
        }
        # os_group=cisco | vendors
        echo PHP_EOL;
    }
    // End While loop on peers
}
示例#11
0
 /**
  * Action to check login credentials
  */
 public function executeLoginCheck()
 {
     $connection = RaykuCommon::getDatabaseConnection();
     $sEmail = trim($this->getRequestParameter('name'));
     $sPassword = trim($this->getRequestParameter('pass'));
     if ($sEmail == '' && $sPassword == '') {
         StatsD::increment("login.failure");
         $this->redirect('login/index');
     }
     //Check the user credentials
     $this->user = UserPeer::checkLogin($sEmail, $sPassword);
     if (!$this->user) {
         StatsD::increment("login.failure");
         $_SESSION['loginErrorMsg'] = 'Your username or password was incorrect.';
     } else {
         StatsD::increment("login.success");
     }
     /**
      * @todo - check if we ever got a chance to hit this place with recaptch - it looks like no so either lets remove it or make it working
      */
     if (isset($_SESSION['loginWrongPass']) && $_SESSION['loginWrongPass'] >= 5) {
         require_once $_SERVER['DOCUMENT_ROOT'] . '/recaptcha/recaptchalib.php';
         // Get a key from https://www.google.com/recaptcha/admin/create
         $publickey = "6Lc_mscSAAAAAE0Bxon37XRl56V_l3Ba0sqib2Zm";
         $privatekey = "6Lc_mscSAAAAAKG3YnU2l3uHYqcBDB6R31XlVTW8";
         # the response from reCAPTCHA
         $resp = null;
         # the error code from reCAPTCHA, if any
         $error = null;
         # was there a reCAPTCHA response?
         $resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
         if ($resp->is_valid) {
             $_SESSION['loginWrongPass'] = 0;
             $_SESSION['recaptchaError'] = '';
         } else {
             # set the error code so that we can display it
             $_SESSION['recaptchaError'] = $resp->error;
             $this->user = false;
         }
     }
     if (!$this->user) {
         $this->msg = 'Your username or password was incorrect.';
         /////incrementing session value plus one if the password is wrong
         $_SESSION['loginWrongPass'] = @$_SESSION['loginWrongPass'] + 1;
         if ($_SESSION['loginWrongPass'] >= 5) {
             $this->redirect("/login");
         }
         return sfView::ERROR;
     }
     //If the user hasn't confirmed their account, display a message
     if ($this->user->isTypeUnconfirmed()) {
         $this->msg = 'You have not confirmed your account yet. Please go to your email inbox and click on the link in the confirmation email.';
         return sfView::ERROR;
     }
     //If the user is banned, display a message
     if ($this->user->getHidden()) {
         $this->msg = 'You are currently banned.';
         return sfView::ERROR;
     }
     $this->getUser()->signIn($this->user, $this->getRequestParameter('remember', false));
     /**
      * Invisible in practice means "invisible until next login"
      * On each login this flag is set either to 0 or 1
      * There is no possibility to change invisible status while being logged in
      */
     $this->user->setInvisible($this->getRequestParameter('invisible', false));
     $_SESSION[$this->user->getUsername()] = time();
     $this->user->save();
     $currentUser = $this->getUser()->getRaykuUser();
     $userId = $currentUser->getId();
     if (!empty($userId)) {
         mysql_query("delete from popup_close where user_id=" . $userId, $connection) or die(mysql_error());
         mysql_query("delete from sendmessage where asker_id =" . $userId, $connection) or die(mysql_error());
         mysql_query("delete from user_expert where checked_id=" . $userId, $connection) or die(mysql_error());
     }
     if (isset($_SESSION['modelPopupOpen'])) {
         unset($_SESSION['modelPopupOpen']);
         if ($_SESSION['popup_session']) {
             unset($_SESSION['popup_session']);
         }
     }
     if ($this->getRequestParameter('referer') != 'http://' . RaykuCommon::getCurrentHttpDomain() . '/login') {
         if ($this->getRequestParameter('referer') != NULL) {
             return $this->redirect($this->getRequestParameter('referer'));
         }
     } else {
         return sfView::SUCCESS;
     }
 }
 public static function statsdIncrement($stat, $prefix = false)
 {
     $_prefix = $prefix ? $prefix : self::statsdPrefix(false, false);
     StatsD::increment($_prefix . $stat);
 }
示例#13
0
<?php

$start = microtime(true);
include 'index.php';
$end = microtime(true);
StatsD::timing("response", round(($end - $start) * 1000, 1));
示例#14
0
                var_dump($value);
                echo "<hr/>";
                fwrite($fp, "{$stat}:{$value}");
            }
            $content = fread($fp, "100");
            var_dump($content);
            echo "<hr color='red'/>";
            fclose($fp);
        } catch (Exception $ex) {
            error_log("StatsD Exception: " . $ex->getMessage());
        }
    }
}
$hostname = "127.0.0.1";
$port_number = 11109;
$statsd = new StatsD($hostname, $port_number);
for ($i = 0; $i < 180; $i++) {
    //<game>.<topic>.<counter_name>
    $statsd->increment('high_level_topic.test.test_counter');
    if ($i % 100 == 0) {
        printf("#");
        sleep(2);
    } else {
        if ($i % 101 == 0) {
            printf("*");
            sleep(2);
        } else {
            printf(".");
            sleep(0.8);
        }
    }
示例#15
0
 private static function makeRequest(array $queryParams, $mode, $json)
 {
     $servers = Z_CONFIG::$CITATION_SERVERS;
     // Try servers in a random order
     shuffle($servers);
     foreach ($servers as $server) {
         $url = "http://" . $server . self::buildURLPath($queryParams, $mode);
         $start = microtime(true);
         $ch = curl_init($url);
         curl_setopt($ch, CURLOPT_POST, 1);
         //error_log("curl -d " . escapeshellarg($json) . " " . escapeshellarg($url));
         curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
         curl_setopt($ch, CURLOPT_HTTPHEADER, array("Expect:"));
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
         curl_setopt($ch, CURLOPT_TIMEOUT, 4);
         curl_setopt($ch, CURLOPT_HEADER, 0);
         // do not return HTTP headers
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $response = curl_exec($ch);
         $time = microtime(true) - $start;
         //error_log("Bib request took " . round($time, 3));
         StatsD::timing("api.cite.{$mode}", $time * 1000);
         $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
         if ($code == 400) {
             throw new Exception("Invalid style", Z_ERROR_CITESERVER_INVALID_STYLE);
         }
         if ($code == 404) {
             throw new Exception("Style not found", Z_ERROR_CITESERVER_INVALID_STYLE);
         }
         if ($code != 200) {
             error_log($code . " from citation server -- trying another " . "[URL: '{$url}'] [INPUT: '{$json}'] [RESPONSE: '{$response}']");
         }
         // If no response, try another server
         if (!$response) {
             continue;
         }
         break;
     }
     if (!$response) {
         throw new Exception("Error generating {$mode}");
     }
     $response = json_decode($response);
     if (!$response) {
         throw new Exception("Error generating {$mode} -- invalid response");
     }
     return $response;
 }
function poll_sensor($device, $class, $unit, &$oid_cache)
{
    global $config, $agent_sensors, $ipmi_sensors;
    $sql = "SELECT *, `sensors`.`sensor_id` AS `sensor_id`";
    $sql .= " FROM  `sensors`";
    $sql .= " LEFT JOIN  `sensors-state` ON  `sensors`.sensor_id =  `sensors-state`.sensor_id";
    $sql .= " WHERE `sensor_class` = ? AND `device_id` = ?";
    foreach (dbFetchRows($sql, array($class, $device['device_id'])) as $sensor) {
        echo "Checking (" . $sensor['poller_type'] . ") {$class} " . $sensor['sensor_descr'] . " ";
        $sensor_new = $sensor;
        // Cache non-humanized sensor array
        humanize_sensor($sensor);
        if ($sensor['poller_type'] == "snmp") {
            # if ($class == "temperature" && $device['os'] == "papouch")
            // Why all temperature?
            if ($class == "temperature" && !$sensor['sensor_state']) {
                for ($i = 0; $i < 5; $i++) {
                    // Take value from $oid_cache if we have it, else snmp_get it
                    if (is_numeric($oid_cache[$sensor['sensor_oid']])) {
                        print_debug("value taken from oid_cache");
                        $sensor_value = $oid_cache[$sensor['sensor_oid']];
                    } else {
                        $sensor_value = preg_replace("/[^0-9\\-\\.]/", "", snmp_get($device, $sensor['sensor_oid'], "-OUqnv", "SNMPv2-MIB", mib_dirs()));
                    }
                    if (is_numeric($sensor_value) && $sensor_value != 9999) {
                        break;
                    }
                    // TME sometimes sends 999.9 when it is right in the middle of an update;
                    sleep(1);
                    # Give the TME some time to reset
                }
                // Also reduce value by 32 if sensor in Fahrenheit unit
                if ($sensor['sensor_divisor'] == 9 && $sensor['sensor_multiplier'] == 5) {
                    $sensor_value -= 32;
                }
            } else {
                if ($class == "runtime" && !$sensor['sensor_state']) {
                    if (isset($oid_cache[$sensor['sensor_oid']])) {
                        print_debug("value taken from oid_cache");
                        $sensor_value = timeticks_to_sec($oid_cache[$sensor['sensor_oid']]);
                    } else {
                        $sensor_value = trim(str_replace("\"", "", snmp_get($device, $sensor['sensor_oid'], "-OUqnv", "SNMPv2-MIB", mib_dirs())));
                        $sensor_value = timeticks_to_sec($sensor_value);
                    }
                } else {
                    // Take value from $oid_cache if we have it, else snmp_get it
                    if (is_numeric($oid_cache[$sensor['sensor_oid']])) {
                        print_debug("value taken from oid_cache");
                        $sensor_value = $oid_cache[$sensor['sensor_oid']];
                    } else {
                        $sensor_value = trim(str_replace("\"", "", snmp_get($device, $sensor['sensor_oid'], "-OUqnv", "SNMPv2-MIB", mib_dirs())));
                    }
                }
            }
        } else {
            if ($sensor['poller_type'] == "agent") {
                if (isset($agent_sensors)) {
                    $sensor_value = $agent_sensors[$class][$sensor['sensor_type']][$sensor['sensor_index']]['current'];
                    # FIXME pass unit?
                } else {
                    print_warning("No agent sensor data.");
                    continue;
                }
            } else {
                if ($sensor['poller_type'] == "ipmi") {
                    if (isset($ipmi_sensors)) {
                        $sensor_value = $ipmi_sensors[$class][$sensor['sensor_type']][$sensor['sensor_index']]['current'];
                        $unit = $ipmi_sensors[$class][$sensor['sensor_type']][$sensor['sensor_index']]['unit'];
                    } else {
                        print_warning("No IPMI sensor data.");
                        continue;
                    }
                } else {
                    print_warning("Unknown sensor poller type.");
                    continue;
                }
            }
        }
        if (!$sensor['sensor_state']) {
            if ($sensor_value == -32768) {
                echo "Invalid (-32768) ";
                $sensor_value = 0;
            }
            if ($sensor['sensor_divisor']) {
                $sensor_value = $sensor_value / $sensor['sensor_divisor'];
            }
            if ($sensor['sensor_multiplier']) {
                $sensor_value = $sensor_value * $sensor['sensor_multiplier'];
            }
        }
        $rrd_file = get_sensor_rrd($device, $sensor);
        if (!is_file($rrd_file)) {
            rrdtool_create($rrd_file, "DS:sensor:GAUGE:600:-20000:U");
            //DS:sensor:GAUGE:600:-20000:20000 ");
        }
        echo "{$sensor_value} {$unit} ";
        // Write new value and humanize (for alert checks)
        $sensor_new['sensor_value'] = $sensor_value;
        humanize_sensor($sensor_new);
        // FIXME also warn when crossing WARN level!!
        if ($sensor['state_event'] != 'ignore') {
            if (!$sensor['sensor_state']) {
                if ($sensor['sensor_limit_low'] != "" && $sensor['sensor_value'] >= $sensor['sensor_limit_low'] && $sensor_value < $sensor['sensor_limit_low']) {
                    $msg = ucfirst($class) . " Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'] . " is under threshold: " . $sensor_value . "{$unit} (< " . $sensor['sensor_limit_low'] . "{$unit})";
                    notify($device, ucfirst($class) . " Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'], $msg);
                    print_message("[%rAlerting for " . $device['hostname'] . " " . $sensor['sensor_descr'] . "%n\n", 'color');
                    log_event(ucfirst($class) . ' ' . $sensor['sensor_descr'] . " under threshold: " . $sensor_value . " {$unit} (< " . $sensor['sensor_limit_low'] . " {$unit})", $device, $class, $sensor['sensor_id']);
                } else {
                    if ($sensor['sensor_limit'] != "" && $sensor['sensor_value'] <= $sensor['sensor_limit'] && $sensor_value > $sensor['sensor_limit']) {
                        $msg = ucfirst($class) . " Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'] . " is over threshold: " . $sensor_value . "{$unit} (> " . $sensor['sensor_limit'] . "{$unit})";
                        notify($device, ucfirst($class) . " Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'], $msg);
                        print_message("[%rAlerting for " . $device['hostname'] . " " . $sensor['sensor_descr'] . "%n\n", 'color');
                        log_event(ucfirst($class) . ' ' . $sensor['sensor_descr'] . " above threshold: " . $sensor_value . " {$unit} (> " . $sensor['sensor_limit'] . " {$unit})", $device, $class, $sensor['sensor_id']);
                    }
                }
            } else {
                if ($sensor_value != $sensor['sensor_value'] && $sensor['state_value'] != '') {
                    $sensor_state_name = $sensor_new['state_name'];
                    $sensor_state_event = $sensor_new['state_event'];
                    switch ($sensor_state_event) {
                        case 'alert':
                            $msg = ucfirst($class) . " Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'] . " is under ALERT state: " . $sensor_state_name . " (previous state: " . $sensor['state_name'] . ")";
                            print_message("[%rSensor ALARM for " . $device['hostname'] . " " . $sensor['sensor_descr'] . "%n\n", 'color');
                            notify($device, ucfirst($class) . " Alarm: " . $device['hostname'] . " " . $sensor['sensor_descr'], $msg);
                            log_event($msg, $device, $class, $sensor['sensor_id']);
                            break;
                        case 'warning':
                            $msg = ucfirst($class) . " Warning: " . $device['hostname'] . " " . $sensor['sensor_descr'] . " in WARNING state: " . $sensor_state_name . " (previous state: " . $sensor['state_name'] . ")";
                            print_message("[%rSensor WARNING for " . $device['hostname'] . " " . $sensor['sensor_descr'] . "%n\n", 'color');
                            log_event($msg, $device, $class, $sensor['sensor_id']);
                            break;
                        case 'up':
                            $msg = ucfirst($class) . " Up: " . $device['hostname'] . " " . $sensor['sensor_descr'] . " in NORMAL state: " . $sensor_state_name . " (previous state: " . $sensor['state_name'] . ")";
                            print_message("[%rSensor UP for " . $device['hostname'] . " " . $sensor['sensor_descr'] . "%n\n", 'color');
                            if ($sensor['state_event'] != 'warning') {
                                notify($device, ucfirst($class) . " Up: " . $device['hostname'] . " " . $sensor['sensor_descr'], $msg);
                            }
                            log_event($msg, $device, $class, $sensor['sensor_id']);
                            break;
                    }
                }
            }
        } else {
            print_message("[%ySensor Ignored%n]", 'color');
        }
        echo "\n";
        // Send statistics array via AMQP/JSON if AMQP is enabled globally and for the ports module
        if ($config['amqp']['enable'] == TRUE && $config['amqp']['modules']['sensors']) {
            $json_data = array('value' => $sensor_value);
            messagebus_send(array('attribs' => array('t' => time(), 'device' => $device['hostname'], 'device_id' => $device['device_id'], 'e_type' => 'sensor', 'e_class' => $sensor['sensor_class'], 'e_type' => $sensor['sensor_type'], 'e_index' => $sensor['sensor_index']), 'data' => $json_data));
        }
        // Update StatsD/Carbon
        if ($config['statsd']['enable'] == TRUE) {
            StatsD::gauge(str_replace(".", "_", $device['hostname']) . '.' . 'sensor' . '.' . $sensor['sensor_class'] . '.' . $sensor['sensor_type'] . '.' . $sensor['sensor_index'], $sensor_value);
        }
        // Update RRD
        rrdtool_update($rrd_file, "N:{$sensor_value}");
        // Check alerts
        if (!$sensor['sensor_state']) {
            check_entity('sensor', $sensor, array('sensor_value' => $sensor_new['sensor_value']));
        }
        check_entity('sensor', $sensor, array('sensor_event' => $sensor_new['state_event']));
        // Update SQL State
        if (is_numeric($sensor['sensor_polled'])) {
            dbUpdate(array('sensor_value' => $sensor_value, 'sensor_polled' => time()), 'sensors-state', '`sensor_id` = ?', array($sensor['sensor_id']));
        } else {
            dbInsert(array('sensor_id' => $sensor['sensor_id'], 'sensor_value' => $sensor_value, 'sensor_polled' => time()), 'sensors-state');
        }
    }
}
示例#17
0
 public function toResponseJSON($requestParams = [])
 {
     $t = microtime(true);
     // Child collections and items can't be cached (easily)
     $numCollections = $this->numCollections();
     $numItems = $this->numItems();
     if (!$requestParams['uncached']) {
         $cacheKey = $this->getCacheKey($requestParams);
         $cached = Z_Core::$MC->get($cacheKey);
         if ($cached) {
             Z_Core::debug("Using cached JSON for {$this->libraryKey}");
             $cached['meta']->numCollections = $numCollections;
             $cached['meta']->numItems = $numItems;
             StatsD::timing("api.collections.toResponseJSON.cached", (microtime(true) - $t) * 1000);
             StatsD::increment("memcached.collections.toResponseJSON.hit");
             return $cached;
         }
     }
     $json = ['key' => $this->key, 'version' => $this->version, 'library' => Zotero_Libraries::toJSON($this->libraryID)];
     // 'links'
     $json['links'] = ['self' => ['href' => Zotero_API::getCollectionURI($this), 'type' => 'application/json'], 'alternate' => ['href' => Zotero_URI::getCollectionURI($this, true), 'type' => 'text/html']];
     $parentID = $this->getParentID();
     if ($parentID) {
         $parentCol = Zotero_Collections::get($this->libraryID, $parentID);
         $json['links']['up'] = ['href' => Zotero_API::getCollectionURI($parentCol), 'type' => "application/atom+xml"];
     }
     // 'meta'
     $json['meta'] = new stdClass();
     $json['meta']->numCollections = $numCollections;
     $json['meta']->numItems = $numItems;
     // 'include'
     $include = $requestParams['include'];
     foreach ($include as $type) {
         if ($type == 'data') {
             $json[$type] = $this->toJSON($requestParams);
         }
     }
     if (!$requestParams['uncached']) {
         Z_Core::$MC->set($cacheKey, $json);
         StatsD::timing("api.collections.toResponseJSON.uncached", (microtime(true) - $t) * 1000);
         StatsD::increment("memcached.collections.toResponseJSON.miss");
     }
     return $json;
 }
示例#18
0
<?php

require_once "includes/functions.inc.php";
require_once "includes/config.inc.php";
$stats = new StatsD();
$action = $_GET['action'];
$software_available = array("gfs", "gfs_hd");
switch ($action) {
    case "getCSV":
        $uuid = $_GET['uuid'];
        $tryfile = PREDS_PATH . $uuid . "/" . FLIGHT_CSV;
        if (!file_exists($tryfile)) {
            return false;
        }
        $fh = fopen($tryfile, "r");
        $data = array();
        while (!feof($fh)) {
            $line = trim(fgets($fh));
            array_push($data, $line);
        }
        $returned = json_encode($data);
        echo $returned;
        $stats->counting('habhub.predictor.php.get_csv');
        break;
    case "JSONexists":
        $uuid = $_GET['uuid'];
        if (file_exists(PREDS_PATH . $uuid . "/" . PROGRESS_JSON)) {
            echo true;
        } else {
            echo false;
        }
示例#19
0
function poll_status($device)
{
    global $config, $agent_sensors, $ipmi_sensors, $graphs, $oid_cache;
    $sql = "SELECT * FROM `status`";
    $sql .= " LEFT JOIN `status-state` USING(`status_id`)";
    $sql .= " WHERE `device_id` = ?";
    foreach (dbFetchRows($sql, array($device['device_id'])) as $status_db) {
        //print_cli_heading("Status: ".$status_db['status_descr']. "(".$status_db['poller_type'].")", 3);
        print_debug("Checking (" . $status_db['poller_type'] . ") " . $status_db['status_descr'] . " ");
        // $status_poll = $status_db;    // Cache non-humanized status array for use as new status state
        if ($status_db['poller_type'] == "snmp") {
            // Check if a specific poller file exists for this status, else collect via SNMP.
            $file = $config['install_dir'] . "/includes/polling/status/" . $status_db['status_type'] . ".inc.php";
            if (is_file($file)) {
                include $file;
            } else {
                // Take value from $oid_cache if we have it, else snmp_get it
                if (is_numeric($oid_cache[$status_db['status_oid']])) {
                    print_debug("value taken from oid_cache");
                    $status_value = $oid_cache[$status_db['status_oid']];
                } else {
                    $status_value = snmp_get($device, $status_db['status_oid'], "-OUqnv", "SNMPv2-MIB");
                }
                $status_value = snmp_fix_numeric($status_value);
            }
        } else {
            if ($status_db['poller_type'] == "agent") {
                if (isset($agent_sensors['state'])) {
                    $status_value = $agent_sensors['state'][$status_db['status_type']][$status_db['status_index']]['current'];
                } else {
                    print_warning("No agent status data available.");
                    continue;
                }
            } else {
                if ($status_db['poller_type'] == "ipmi") {
                    if (isset($ipmi_sensors['state'])) {
                        $status_value = $ipmi_sensors['state'][$status_db['status_type']][$status_db['status_index']]['current'];
                    } else {
                        print_warning("No IPMI status data available.");
                        continue;
                    }
                } else {
                    print_warning("Unknown status poller type.");
                    continue;
                }
            }
        }
        $status_polled_time = time();
        // Store polled time for current status
        // Write new value and humanize (for alert checks)
        $state_array = get_state_array($status_db['status_type'], $status_value, $status_db['poller_type']);
        $status_poll['status_value'] = $state_array['value'];
        $status_poll['status_name'] = $state_array['name'];
        if ($status_db['status_ignore'] || $status_db['status_disable']) {
            $status_poll['status_event'] = 'ignore';
        } else {
            $status_poll['status_event'] = $state_array['event'];
        }
        // If last change never set, use current time
        if (empty($status_db['status_last_change'])) {
            $status_db['status_last_change'] = $status_polled_time;
        }
        if ($status_poll['status_event'] != $status_db['status_event']) {
            // Status event changed, log and set status_last_change
            $status_poll['status_last_change'] = $status_polled_time;
            if ($status_poll['status_event'] == 'ignore') {
                print_message("[%ystatus Ignored%n]", 'color');
            } else {
                if ($status_db['status_event'] != '') {
                    // If old state not empty and new state not equals to new state
                    $msg = 'Status ';
                    switch ($status_poll['status_event']) {
                        case 'alert':
                            // New state alerted
                            $msg .= "Alert: " . $device['hostname'] . " " . $status_db['status_descr'] . " entered ALERT state: " . $status_poll['status_name'] . " (previous: " . $status_db['status_name'] . ")";
                            log_event($msg, $device, 'status', $status_db['status_id'], 'warning');
                            break;
                        case 'warning':
                            // New state warned
                            $msg .= "Warning: " . $device['hostname'] . " " . $status_db['status_descr'] . " entered WARNING state: " . $status_poll['status_name'] . " (previous: " . $status_db['status_name'] . ")";
                            log_event($msg, $device, 'status', $status_db['status_id']);
                            break;
                        case 'ok':
                            // New state ok
                            $msg .= "Ok: " . $device['hostname'] . " " . $status_db['status_descr'] . " entered OK state: " . $status_poll['status_name'] . " (previous: " . $status_db['status_name'] . ")";
                            log_event($msg, $device, 'status', $status_db['status_id'], 'warning');
                            break;
                    }
                }
            }
        } else {
            // If status not changed, leave old last_change
            $status_poll['status_last_change'] = $status_db['status_last_change'];
        }
        if (OBS_DEBUG > 1) {
            print_vars($status_poll);
        }
        // Send statistics array via AMQP/JSON if AMQP is enabled globally and for the ports module
        if ($config['amqp']['enable'] == TRUE && $config['amqp']['modules']['status']) {
            $json_data = array('value' => $status_value);
            messagebus_send(array('attribs' => array('t' => time(), 'device' => $device['hostname'], 'device_id' => $device['device_id'], 'e_type' => 'status', 'e_type' => $status_db['status_type'], 'e_index' => $status_db['status_index']), 'data' => $json_data));
        }
        // Update StatsD/Carbon
        if ($config['statsd']['enable'] == TRUE) {
            StatsD::gauge(str_replace(".", "_", $device['hostname']) . '.' . 'status' . '.' . $status_db['status_class'] . '.' . $status_db['status_type'] . '.' . $status_db['status_index'], $status_value);
        }
        // Update RRD - FIXME - can't convert to NG because filename is dynamic! new function should return index instead of filename.
        $rrd_file = get_status_rrd($device, $status_db);
        rrdtool_create($device, $rrd_file, "DS:status:GAUGE:600:-20000:U");
        rrdtool_update($device, $rrd_file, "N:{$status_value}");
        // Enable graph
        $graphs[$sensor_db['status']] = TRUE;
        // Check alerts
        $metrics = array();
        $metrics['status_value'] = $status_value;
        $metrics['status_name'] = $status_poll['status_name'];
        $metrics['status_name_uptime'] = $status_polled_time - $status_poll['status_last_change'];
        $metrics['status_event'] = $status_poll['status_event'];
        //print_cli_data("Event (State)", $status_poll['status_event'] ." (".$status_poll['status_name'].")", 3);
        $GLOBALS['table_rows'][] = array($status_db['status_descr'], $status_db['status_type'], $status_db['status_index'], $status_db['poller_type'], $status_poll['status_name'], $status_poll['status_event'], format_unixtime($status_poll['status_last_change']));
        check_entity('status', $status_db, $metrics);
        // Update SQL State
        if (is_numeric($status_db['status_polled'])) {
            dbUpdate(array('status_value' => $status_value, 'status_name' => $status_poll['status_name'], 'status_event' => $status_poll['status_event'], 'status_last_change' => $status_poll['status_last_change'], 'status_polled' => $status_polled_time), 'status-state', '`status_id` = ?', array($status_db['status_id']));
        } else {
            dbInsert(array('status_id' => $status_db['status_id'], 'status_value' => $status_value, 'status_name' => $status_poll['status_name'], 'status_event' => $status_poll['status_event'], 'status_last_change' => $status_poll['status_last_change'], 'status_polled' => $status_polled_time), 'status-state');
        }
    }
}
     continue;
 }
 if (OBS_DEBUG && count($storage)) {
     print_vars($storage);
 }
 if ($storage['size']) {
     $percent = round($storage['used'] / $storage['size'] * 100, 2);
 } else {
     $percent = 0;
 }
 $hc = $storage['storage_hc'] ? ' (HC)' : '';
 print_message("存储 " . $storage['storage_descr'] . ': ' . $percent . '%%' . $hc);
 // Update StatsD/Carbon
 if ($config['statsd']['enable'] == TRUE) {
     StatsD::gauge(str_replace(".", "_", $device['hostname']) . '.' . 'storage' . '.' . $storage['storage_mib'] . "-" . safename($storage['storage_descr']) . ".used", $storage['used']);
     StatsD::gauge(str_replace(".", "_", $device['hostname']) . '.' . 'storage' . '.' . $storage['storage_mib'] . "-" . safename($storage['storage_descr']) . ".free", $storage['free']);
 }
 // Update RRD
 rrdtool_update($device, $storage_rrd, "N:" . $storage['used'] . ":" . $storage['free']);
 if (!is_numeric($storage['storage_polled'])) {
     dbInsert(array('storage_id' => $storage['storage_id'], 'storage_polled' => time(), 'storage_used' => $storage['used'], 'storage_free' => $storage['free'], 'storage_size' => $storage['size'], 'storage_units' => $storage['units'], 'storage_perc' => $percent), 'storage-state');
 } else {
     $update = dbUpdate(array('storage_polled' => time(), 'storage_used' => $storage['used'], 'storage_free' => $storage['free'], 'storage_size' => $storage['size'], 'storage_units' => $storage['units'], 'storage_perc' => $percent), 'storage-state', '`storage_id` = ?', array($storage['storage_id']));
     if ($storage_size != $storage['storage_size']) {
         log_event('存储容量变更: ' . formatStorage($storage_size) . ' -> ' . formatStorage($storage['storage_size']) . ' (' . $storage['storage_descr'] . ')', $device, 'storage', $storage['storage_id']);
     }
 }
 $graphs['storage'] = TRUE;
 // Check alerts
 check_entity('storage', $storage, array('storage_perc' => $percent, 'storage_free' => $storage['free'], 'storage_used' => $storage['used']));
 echo PHP_EOL;
示例#21
0
 private static function processDownloadInternal($userID, $lastsync, DOMDocument $doc, $syncDownloadQueueID = null, $syncDownloadProcessID = null, $params = [])
 {
     $apiVersion = (int) $doc->documentElement->getAttribute('version');
     if ($lastsync == 1) {
         StatsD::increment("sync.process.download.full");
     }
     // TEMP
     $cacheKeyExtra = (!empty($params['ft']) ? json_encode($params['ft']) : "") . (!empty($params['ftkeys']) ? json_encode($params['ftkeys']) : "");
     try {
         $cached = Zotero_Sync::getCachedDownload($userID, $lastsync, $apiVersion, $cacheKeyExtra);
         if ($cached) {
             $doc->loadXML($cached);
             StatsD::increment("sync.process.download.cache.hit");
             return;
         }
     } catch (Exception $e) {
         $msg = $e->getMessage();
         if (strpos($msg, "Too many connections") !== false) {
             $msg = "'Too many connections' from MySQL";
         } else {
             $msg = "'{$msg}'";
         }
         Z_Core::logError("Warning: {$msg} getting cached download");
         StatsD::increment("sync.process.download.cache.error");
     }
     set_time_limit(1800);
     $profile = false;
     if ($profile) {
         $shardID = Zotero_Shards::getByUserID($userID);
         Zotero_DB::profileStart(0);
     }
     if ($syncDownloadQueueID) {
         self::addDownloadProcess($syncDownloadQueueID, $syncDownloadProcessID);
     }
     $updatedNode = $doc->createElement('updated');
     $doc->documentElement->appendChild($updatedNode);
     $userLibraryID = Zotero_Users::getLibraryIDFromUserID($userID);
     $updatedCreators = array();
     try {
         Zotero_DB::beginTransaction();
         // Blocks until any upload processes are done
         $updateTimes = Zotero_Libraries::getUserLibraryUpdateTimes($userID);
         $timestamp = Zotero_DB::getTransactionTimestampUnix();
         $doc->documentElement->setAttribute('timestamp', $timestamp);
         $doc->documentElement->setAttribute('userID', $userID);
         $doc->documentElement->setAttribute('defaultLibraryID', $userLibraryID);
         $updateKey = Zotero_Users::getUpdateKey($userID);
         $doc->documentElement->setAttribute('updateKey', $updateKey);
         // Get libraries with update times >= $timestamp
         $updatedLibraryIDs = array();
         foreach ($updateTimes as $libraryID => $timestamp) {
             if ($timestamp >= $lastsync) {
                 $updatedLibraryIDs[] = $libraryID;
             }
         }
         // Add new and updated groups
         $joinedGroups = Zotero_Groups::getJoined($userID, (int) $lastsync);
         $updatedIDs = array_unique(array_merge($joinedGroups, Zotero_Groups::getUpdated($userID, (int) $lastsync)));
         if ($updatedIDs) {
             $node = $doc->createElement('groups');
             $showGroups = false;
             foreach ($updatedIDs as $id) {
                 $group = new Zotero_Group();
                 $group->id = $id;
                 $xmlElement = $group->toXML($userID);
                 $newNode = dom_import_simplexml($xmlElement);
                 $newNode = $doc->importNode($newNode, true);
                 $node->appendChild($newNode);
                 $showGroups = true;
             }
             if ($showGroups) {
                 $updatedNode->appendChild($node);
             }
         }
         // If there's updated data in any library or
         // there are any new groups (in which case we need all their data)
         $hasData = $updatedLibraryIDs || $joinedGroups;
         if ($hasData) {
             foreach (Zotero_DataObjects::$classicObjectTypes as $syncObject) {
                 $Name = $syncObject['singular'];
                 // 'Item'
                 $Names = $syncObject['plural'];
                 // 'Items'
                 $name = strtolower($Name);
                 // 'item'
                 $names = strtolower($Names);
                 // 'items'
                 $className = 'Zotero_' . $Names;
                 $updatedIDsByLibraryID = call_user_func(array($className, 'getUpdated'), $userID, $lastsync, $updatedLibraryIDs);
                 if ($updatedIDsByLibraryID) {
                     $node = $doc->createElement($names);
                     foreach ($updatedIDsByLibraryID as $libraryID => $ids) {
                         if ($name == 'creator') {
                             $updatedCreators[$libraryID] = $ids;
                         }
                         foreach ($ids as $id) {
                             if ($name == 'item') {
                                 $obj = call_user_func(array($className, 'get'), $libraryID, $id);
                                 $data = array('updatedCreators' => isset($updatedCreators[$libraryID]) ? $updatedCreators[$libraryID] : array());
                                 $xmlElement = Zotero_Items::convertItemToXML($obj, $data, $apiVersion);
                             } else {
                                 $instanceClass = 'Zotero_' . $Name;
                                 $obj = new $instanceClass();
                                 if (method_exists($instanceClass, '__construct')) {
                                     $obj->__construct();
                                 }
                                 $obj->libraryID = $libraryID;
                                 if ($name == 'setting') {
                                     $obj->name = $id;
                                 } else {
                                     $obj->id = $id;
                                 }
                                 if ($name == 'tag') {
                                     $xmlElement = call_user_func(array($className, "convert{$Name}ToXML"), $obj, true);
                                 } else {
                                     if ($name == 'creator') {
                                         $xmlElement = call_user_func(array($className, "convert{$Name}ToXML"), $obj, $doc);
                                         if ($xmlElement->getAttribute('libraryID') == $userLibraryID) {
                                             $xmlElement->removeAttribute('libraryID');
                                         }
                                         $node->appendChild($xmlElement);
                                     } else {
                                         if ($name == 'relation') {
                                             // Skip new-style related items
                                             if ($obj->predicate == 'dc:relation') {
                                                 continue;
                                             }
                                             $xmlElement = call_user_func(array($className, "convert{$Name}ToXML"), $obj);
                                             if ($apiVersion <= 8) {
                                                 unset($xmlElement['libraryID']);
                                             }
                                         } else {
                                             if ($name == 'setting') {
                                                 $xmlElement = call_user_func(array($className, "convert{$Name}ToXML"), $obj, $doc);
                                                 $node->appendChild($xmlElement);
                                             } else {
                                                 $xmlElement = call_user_func(array($className, "convert{$Name}ToXML"), $obj);
                                             }
                                         }
                                     }
                                 }
                             }
                             if ($xmlElement instanceof SimpleXMLElement) {
                                 if ($xmlElement['libraryID'] == $userLibraryID) {
                                     unset($xmlElement['libraryID']);
                                 }
                                 $newNode = dom_import_simplexml($xmlElement);
                                 $newNode = $doc->importNode($newNode, true);
                                 $node->appendChild($newNode);
                             }
                         }
                     }
                     if ($node->hasChildNodes()) {
                         $updatedNode->appendChild($node);
                     }
                 }
             }
         }
         // Add full-text content if the client supports it
         if (isset($params['ft'])) {
             $libraries = Zotero_Libraries::getUserLibraries($userID);
             $fulltextNode = false;
             foreach ($libraries as $libraryID) {
                 if (!empty($params['ftkeys']) && $params['ftkeys'] === 'all') {
                     $ftlastsync = 1;
                 } else {
                     $ftlastsync = $lastsync;
                 }
                 if (!empty($params['ftkeys'][$libraryID])) {
                     $keys = $params['ftkeys'][$libraryID];
                 } else {
                     $keys = [];
                 }
                 $data = Zotero_FullText::getNewerInLibraryByTime($libraryID, $ftlastsync, $keys);
                 if ($data) {
                     if (!$fulltextNode) {
                         $fulltextNode = $doc->createElement('fulltexts');
                     }
                     foreach ($data as $itemData) {
                         if ($params['ft']) {
                             $empty = $itemData['empty'];
                         } else {
                             $empty = true;
                         }
                         $first = false;
                         $node = Zotero_FullText::itemDataToXML($itemData, $doc, $empty);
                         $fulltextNode->appendChild($node);
                     }
                 }
             }
             if ($fulltextNode) {
                 $updatedNode->appendChild($fulltextNode);
             }
         }
         // Get earliest timestamp
         $earliestModTime = Zotero_Users::getEarliestDataTimestamp($userID);
         $doc->documentElement->setAttribute('earliest', $earliestModTime ? $earliestModTime : 0);
         // Deleted objects
         $deletedKeys = $hasData ? self::getDeletedObjectKeys($userID, $lastsync, true) : false;
         $deletedIDs = self::getDeletedObjectIDs($userID, $lastsync, true);
         if ($deletedKeys || $deletedIDs) {
             $deletedNode = $doc->createElement('deleted');
             // Add deleted data objects
             if ($deletedKeys) {
                 foreach (Zotero_DataObjects::$classicObjectTypes as $syncObject) {
                     $Name = $syncObject['singular'];
                     // 'Item'
                     $Names = $syncObject['plural'];
                     // 'Items'
                     $name = strtolower($Name);
                     // 'item'
                     $names = strtolower($Names);
                     // 'items'
                     if (empty($deletedKeys[$names])) {
                         continue;
                     }
                     $typeNode = $doc->createElement($names);
                     foreach ($deletedKeys[$names] as $row) {
                         $node = $doc->createElement($name);
                         if ($row['libraryID'] != $userLibraryID || $name == 'setting') {
                             $node->setAttribute('libraryID', $row['libraryID']);
                         }
                         $node->setAttribute('key', $row['key']);
                         $typeNode->appendChild($node);
                     }
                     $deletedNode->appendChild($typeNode);
                 }
             }
             // Add deleted groups
             if ($deletedIDs) {
                 $name = "group";
                 $names = "groups";
                 $typeNode = $doc->createElement($names);
                 $ids = $doc->createTextNode(implode(' ', $deletedIDs[$names]));
                 $typeNode->appendChild($ids);
                 $deletedNode->appendChild($typeNode);
             }
             $updatedNode->appendChild($deletedNode);
         }
         Zotero_DB::commit();
     } catch (Exception $e) {
         Zotero_DB::rollback(true);
         if ($syncDownloadQueueID) {
             self::removeDownloadProcess($syncDownloadProcessID);
         }
         throw $e;
     }
     function relaxNGErrorHandler($errno, $errstr)
     {
         Zotero_Sync::$validationError = $errstr;
     }
     set_error_handler('relaxNGErrorHandler');
     $valid = $doc->relaxNGValidate(Z_ENV_MODEL_PATH . 'relax-ng/updated.rng');
     restore_error_handler();
     if (!$valid) {
         if ($syncDownloadQueueID) {
             self::removeDownloadProcess($syncDownloadProcessID);
         }
         throw new Exception(self::$validationError . "\n\nXML:\n\n" . $doc->saveXML());
     }
     // Cache response if response isn't empty
     try {
         if ($doc->documentElement->firstChild->hasChildNodes()) {
             self::cacheDownload($userID, $updateKey, $lastsync, $apiVersion, $doc->saveXML(), $cacheKeyExtra);
         }
     } catch (Exception $e) {
         Z_Core::logError("WARNING: " . $e);
     }
     if ($syncDownloadQueueID) {
         self::removeDownloadProcess($syncDownloadProcessID);
     }
     if ($profile) {
         $shardID = Zotero_Shards::getByUserID($userID);
         Zotero_DB::profileEnd(0);
     }
 }
示例#22
0
 /**
  * Handle S3 request
  *
  * Permission-checking provided by items()
  */
 private function _handleFileRequest($item)
 {
     if (!$this->permissions->canAccess($this->objectLibraryID, 'files')) {
         $this->e403();
     }
     $this->allowMethods(array('HEAD', 'GET', 'POST', 'PATCH'));
     if (!$item->isAttachment()) {
         $this->e400("Item is not an attachment");
     }
     // File info for 4.0 client sync
     //
     // Use of HEAD method was discontinued after 2.0.8/2.1b1 due to
     // compatibility problems with proxies and security software
     if ($this->method == 'GET' && $this->fileMode == 'info') {
         $info = Zotero_Storage::getLocalFileItemInfo($item);
         if (!$info) {
             $this->e404();
         }
         StatsD::increment("storage.info", 1);
         /*
         header("Last-Modified: " . gmdate('r', $info['uploaded']));
         header("Content-Type: " . $info['type']);
         */
         header("Content-Length: " . $info['size']);
         header("ETag: " . $info['hash']);
         header("X-Zotero-Filename: " . $info['filename']);
         header("X-Zotero-Modification-Time: " . $info['mtime']);
         header("X-Zotero-Compressed: " . ($info['zip'] ? 'Yes' : 'No'));
         header_remove("X-Powered-By");
         $this->end();
     } else {
         if ($this->method == 'GET') {
             $info = Zotero_Storage::getLocalFileItemInfo($item);
             if (!$info) {
                 $this->e404();
             }
             // File viewing
             if ($this->fileView) {
                 $url = Zotero_Attachments::getTemporaryURL($item, !empty($_GET['int']));
                 if (!$url) {
                     $this->e500();
                 }
                 StatsD::increment("storage.view", 1);
                 $this->redirect($url);
                 exit;
             }
             // File download
             $url = Zotero_Storage::getDownloadURL($item, 60);
             if (!$url) {
                 $this->e404();
             }
             // Provide some headers to let 5.0 client skip download
             header("Zotero-File-Modification-Time: {$info['mtime']}");
             header("Zotero-File-MD5: {$info['hash']}");
             header("Zotero-File-Size: {$info['size']}");
             header("Zotero-File-Compressed: " . ($info['zip'] ? 'Yes' : 'No'));
             StatsD::increment("storage.download", 1);
             Zotero_Storage::logDownload($item, $this->userID, IPAddress::getIP());
             $this->redirect($url);
             exit;
         } else {
             if ($this->method == 'POST' || $this->method == 'PATCH') {
                 if (!$item->isImportedAttachment()) {
                     $this->e400("Cannot upload file for linked file/URL attachment item");
                 }
                 $libraryID = $item->libraryID;
                 $type = Zotero_Libraries::getType($libraryID);
                 if ($type == 'group') {
                     $groupID = Zotero_Groups::getGroupIDFromLibraryID($libraryID);
                     $group = Zotero_Groups::get($groupID);
                     if (!$group->userCanEditFiles($this->userID)) {
                         $this->e403("You do not have file editing access");
                     }
                 } else {
                     $group = null;
                 }
                 // If not the client, require If-Match or If-None-Match
                 if (!$this->httpAuth) {
                     if (empty($_SERVER['HTTP_IF_MATCH']) && empty($_SERVER['HTTP_IF_NONE_MATCH'])) {
                         $this->e428("If-Match/If-None-Match header not provided");
                     }
                     if (!empty($_SERVER['HTTP_IF_MATCH'])) {
                         if (!preg_match('/^"?([a-f0-9]{32})"?$/', $_SERVER['HTTP_IF_MATCH'], $matches)) {
                             $this->e400("Invalid ETag in If-Match header");
                         }
                         if (!$item->attachmentStorageHash) {
                             $this->e412("ETag set but file does not exist");
                         }
                         if ($item->attachmentStorageHash != $matches[1]) {
                             $this->libraryVersion = $item->version;
                             $this->libraryVersionOnFailure = true;
                             $this->e412("ETag does not match current version of file");
                         }
                     } else {
                         if ($_SERVER['HTTP_IF_NONE_MATCH'] != "*") {
                             $this->e400("Invalid value for If-None-Match header");
                         }
                         if (Zotero_Storage::getLocalFileItemInfo($item)) {
                             $this->libraryVersion = $item->version;
                             $this->libraryVersionOnFailure = true;
                             $this->e412("If-None-Match: * set but file exists");
                         }
                     }
                 }
                 //
                 // Upload authorization
                 //
                 if (!isset($_POST['update']) && !isset($_REQUEST['upload'])) {
                     $info = new Zotero_StorageFileInfo();
                     // Validate upload metadata
                     if (empty($_REQUEST['md5'])) {
                         $this->e400('MD5 hash not provided');
                     }
                     if (!preg_match('/[abcdefg0-9]{32}/', $_REQUEST['md5'])) {
                         $this->e400('Invalid MD5 hash');
                     }
                     if (!isset($_REQUEST['filename']) || $_REQUEST['filename'] === "") {
                         $this->e400('Filename not provided');
                     }
                     // Multi-file upload
                     //
                     // For ZIP files, the filename and hash of the ZIP file are different from those
                     // of the main file. We use the former for S3, and we store the latter in the
                     // upload log to set the attachment metadata with them on file registration.
                     if (!empty($_REQUEST['zipMD5'])) {
                         if (!preg_match('/[abcdefg0-9]{32}/', $_REQUEST['zipMD5'])) {
                             $this->e400('Invalid ZIP MD5 hash');
                         }
                         if (empty($_REQUEST['zipFilename'])) {
                             $this->e400('ZIP filename not provided');
                         }
                         $info->zip = true;
                         $info->hash = $_REQUEST['zipMD5'];
                         $info->filename = $_REQUEST['zipFilename'];
                         $info->itemFilename = $_REQUEST['filename'];
                         $info->itemHash = $_REQUEST['md5'];
                     } else {
                         if (!empty($_REQUEST['zipFilename'])) {
                             $this->e400('ZIP MD5 hash not provided');
                         } else {
                             $info->zip = !empty($_REQUEST['zip']);
                             $info->filename = $_REQUEST['filename'];
                             $info->hash = $_REQUEST['md5'];
                         }
                     }
                     if (empty($_REQUEST['mtime'])) {
                         $this->e400('File modification time not provided');
                     }
                     $info->mtime = $_REQUEST['mtime'];
                     if (!isset($_REQUEST['filesize'])) {
                         $this->e400('File size not provided');
                     }
                     $info->size = $_REQUEST['filesize'];
                     if (!is_numeric($info->size)) {
                         $this->e400("Invalid file size");
                     }
                     $info->contentType = isset($_REQUEST['contentType']) ? $_REQUEST['contentType'] : null;
                     if (!preg_match("/^[a-zA-Z0-9\\-\\/]+\$/", $info->contentType)) {
                         $info->contentType = null;
                     }
                     $info->charset = isset($_REQUEST['charset']) ? $_REQUEST['charset'] : null;
                     if (!preg_match("/^[a-zA-Z0-9\\-]+\$/", $info->charset)) {
                         $info->charset = null;
                     }
                     $contentTypeHeader = $info->contentType . ($info->contentType && $info->charset ? "; charset=" . $info->charset : "");
                     // Reject file if it would put account over quota
                     if ($group) {
                         $quota = Zotero_Storage::getEffectiveUserQuota($group->ownerUserID);
                         $usage = Zotero_Storage::getUserUsage($group->ownerUserID);
                     } else {
                         $quota = Zotero_Storage::getEffectiveUserQuota($this->objectUserID);
                         $usage = Zotero_Storage::getUserUsage($this->objectUserID);
                     }
                     $total = $usage['total'];
                     $fileSizeMB = round($info->size / 1024 / 1024, 1);
                     if ($total + $fileSizeMB > $quota) {
                         StatsD::increment("storage.upload.quota", 1);
                         $this->e413("File would exceed quota ({$total} + {$fileSizeMB} > {$quota})");
                     }
                     Zotero_DB::query("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE");
                     Zotero_DB::beginTransaction();
                     // See if file exists with this filename
                     $localInfo = Zotero_Storage::getLocalFileInfo($info);
                     if ($localInfo) {
                         $storageFileID = $localInfo['storageFileID'];
                         // Verify file size
                         if ($localInfo['size'] != $info->size) {
                             throw new Exception("Specified file size incorrect for existing file " . $info->hash . "/" . $info->filename . " ({$localInfo['size']} != {$info->size})");
                         }
                     } else {
                         $oldStorageFileID = Zotero_Storage::getFileByHash($info->hash, $info->zip);
                         if ($oldStorageFileID) {
                             // Verify file size
                             $localInfo = Zotero_Storage::getFileInfoByID($oldStorageFileID);
                             if ($localInfo['size'] != $info->size) {
                                 throw new Exception("Specified file size incorrect for duplicated file " . $info->hash . "/" . $info->filename . " ({$localInfo['size']} != {$info->size})");
                             }
                             // Create new file on S3 with new name
                             $storageFileID = Zotero_Storage::duplicateFile($oldStorageFileID, $info->filename, $info->zip, $contentTypeHeader);
                         }
                     }
                     // If we already have a file, add/update storageFileItems row and stop
                     if (!empty($storageFileID)) {
                         Zotero_Storage::updateFileItemInfo($item, $storageFileID, $info, $this->httpAuth);
                         Zotero_DB::commit();
                         StatsD::increment("storage.upload.existing", 1);
                         if ($this->httpAuth) {
                             $this->queryParams['format'] = null;
                             header('Content-Type: application/xml');
                             echo "<exists/>";
                         } else {
                             $this->queryParams['format'] = null;
                             header('Content-Type: application/json');
                             $this->libraryVersion = $item->version;
                             echo json_encode(array('exists' => 1));
                         }
                         $this->end();
                     }
                     Zotero_DB::commit();
                     // Add request to upload queue
                     $uploadKey = Zotero_Storage::queueUpload($this->userID, $info);
                     // User over queue limit
                     if (!$uploadKey) {
                         header('Retry-After: ' . Zotero_Storage::$uploadQueueTimeout);
                         if ($this->httpAuth) {
                             $this->e413("Too many queued uploads");
                         } else {
                             $this->e429("Too many queued uploads");
                         }
                     }
                     StatsD::increment("storage.upload.new", 1);
                     // Output XML for client requests (which use HTTP Auth)
                     if ($this->httpAuth) {
                         $params = Zotero_Storage::generateUploadPOSTParams($item, $info, true);
                         $this->queryParams['format'] = null;
                         header('Content-Type: application/xml');
                         $xml = new SimpleXMLElement('<upload/>');
                         $xml->url = Zotero_Storage::getUploadBaseURL();
                         $xml->key = $uploadKey;
                         foreach ($params as $key => $val) {
                             $xml->params->{$key} = $val;
                         }
                         echo $xml->asXML();
                     } else {
                         if (!empty($_REQUEST['params']) && $_REQUEST['params'] == "1") {
                             $params = array("url" => Zotero_Storage::getUploadBaseURL(), "params" => array());
                             foreach (Zotero_Storage::generateUploadPOSTParams($item, $info) as $key => $val) {
                                 $params['params'][$key] = $val;
                             }
                         } else {
                             $params = Zotero_Storage::getUploadPOSTData($item, $info);
                         }
                         $params['uploadKey'] = $uploadKey;
                         $this->queryParams['format'] = null;
                         header('Content-Type: application/json');
                         echo json_encode($params);
                     }
                     exit;
                 }
                 //
                 // API partial upload and post-upload file registration
                 //
                 if (isset($_REQUEST['upload'])) {
                     $uploadKey = $_REQUEST['upload'];
                     if (!$uploadKey) {
                         $this->e400("Upload key not provided");
                     }
                     $info = Zotero_Storage::getUploadInfo($uploadKey);
                     if (!$info) {
                         $this->e400("Upload key not found");
                     }
                     // Partial upload
                     if ($this->method == 'PATCH') {
                         if (empty($_REQUEST['algorithm'])) {
                             throw new Exception("Algorithm not specified", Z_ERROR_INVALID_INPUT);
                         }
                         $storageFileID = Zotero_Storage::patchFile($item, $info, $_REQUEST['algorithm'], $this->body);
                     } else {
                         $remoteInfo = Zotero_Storage::getRemoteFileInfo($info);
                         if (!$remoteInfo) {
                             error_log("Remote file {$info->hash}/{$info->filename} not found");
                             $this->e400("Remote file not found");
                         }
                         if ($remoteInfo->size != $info->size) {
                             error_log("Uploaded file size does not match " . "({$remoteInfo->size} != {$info->size}) " . "for file {$info->hash}/{$info->filename}");
                         }
                     }
                     // Set an automatic shared lock in getLocalFileInfo() to prevent
                     // two simultaneous transactions from adding a file
                     Zotero_DB::query("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE");
                     Zotero_DB::beginTransaction();
                     if (!isset($storageFileID)) {
                         // Check if file already exists, which can happen if two identical
                         // files are uploaded simultaneously
                         $fileInfo = Zotero_Storage::getLocalFileInfo($info);
                         if ($fileInfo) {
                             $storageFileID = $fileInfo['storageFileID'];
                         } else {
                             $storageFileID = Zotero_Storage::addFile($info);
                         }
                     }
                     Zotero_Storage::updateFileItemInfo($item, $storageFileID, $info);
                     Zotero_Storage::logUpload($this->userID, $item, $uploadKey, IPAddress::getIP());
                     Zotero_DB::commit();
                     header("HTTP/1.1 204 No Content");
                     header("Last-Modified-Version: " . $item->version);
                     exit;
                 }
                 //
                 // Client post-upload file registration
                 //
                 if (isset($_POST['update'])) {
                     $this->allowMethods(array('POST'));
                     if (empty($_POST['mtime'])) {
                         throw new Exception('File modification time not provided');
                     }
                     $uploadKey = $_POST['update'];
                     $info = Zotero_Storage::getUploadInfo($uploadKey);
                     if (!$info) {
                         $this->e400("Upload key not found");
                     }
                     $remoteInfo = Zotero_Storage::getRemoteFileInfo($info);
                     if (!$remoteInfo) {
                         $this->e400("Remote file not found");
                     }
                     if (!isset($info->size)) {
                         throw new Exception("Size information not available");
                     }
                     $info->mtime = $_POST['mtime'];
                     // Set an automatic shared lock in getLocalFileInfo() to prevent
                     // two simultaneous transactions from adding a file
                     Zotero_DB::query("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE");
                     Zotero_DB::beginTransaction();
                     // Check if file already exists, which can happen if two identical
                     // files are uploaded simultaneously
                     $fileInfo = Zotero_Storage::getLocalFileInfo($info);
                     if ($fileInfo) {
                         $storageFileID = $fileInfo['storageFileID'];
                     } else {
                         $storageFileID = Zotero_Storage::addFile($info);
                     }
                     Zotero_Storage::updateFileItemInfo($item, $storageFileID, $info, true);
                     Zotero_Storage::logUpload($this->userID, $item, $uploadKey, IPAddress::getIP());
                     Zotero_DB::commit();
                     header("HTTP/1.1 204 No Content");
                     exit;
                 }
                 throw new Exception("Invalid request", Z_ERROR_INVALID_INPUT);
             }
         }
     }
     exit;
 }
示例#23
0
 public function toResponseJSON($requestParams = [], Zotero_Permissions $permissions, $sharedData = null)
 {
     $t = microtime(true);
     if (!$this->loaded['primaryData']) {
         $this->loadPrimaryData();
     }
     if (!$this->loaded['itemData']) {
         $this->loadItemData();
     }
     // Uncached stuff or parts of the cache key
     $version = $this->version;
     $parent = $this->getSource();
     $isRegularItem = !$parent && $this->isRegularItem();
     $downloadDetails = $permissions->canAccess($this->libraryID, 'files') ? Zotero_Storage::getDownloadDetails($this) : false;
     if ($isRegularItem) {
         $numChildren = $permissions->canAccess($this->libraryID, 'notes') ? $this->numChildren() : $this->numAttachments();
     }
     $libraryType = Zotero_Libraries::getType($this->libraryID);
     // Any query parameters that have an effect on the output
     // need to be added here
     $allowedParams = ['include', 'style', 'css', 'linkwrap'];
     $cachedParams = Z_Array::filterKeys($requestParams, $allowedParams);
     $cacheVersion = 1;
     $cacheKey = "jsonEntry_" . $this->libraryID . "/" . $this->id . "_" . md5($version . json_encode($cachedParams) . ($downloadDetails ? 'hasFile' : '') . ($libraryType == 'group' ? Zotero_URI::getItemURI($this, true) : '')) . "_" . $requestParams['v'] . "_" . $cacheVersion . (isset(Z_CONFIG::$CACHE_VERSION_RESPONSE_JSON_ITEM) ? "_" . Z_CONFIG::$CACHE_VERSION_RESPONSE_JSON_ITEM : "") . (in_array('bib', $requestParams['include']) && isset(Z_CONFIG::$CACHE_VERSION_BIB) ? "_" . Z_CONFIG::$CACHE_VERSION_BIB : "");
     $cached = Z_Core::$MC->get($cacheKey);
     if (false && $cached) {
         // Make sure numChildren reflects the current permissions
         if ($isRegularItem) {
             $cached['meta']->numChildren = $numChildren;
         }
         StatsD::timing("api.items.itemToResponseJSON.cached", (microtime(true) - $t) * 1000);
         StatsD::increment("memcached.items.itemToResponseJSON.hit");
         // Skip the cache every 10 times for now, to ensure cache sanity
         if (!Z_Core::probability(10)) {
             return $cached;
         }
     }
     $json = ['key' => $this->key, 'version' => $version, 'library' => Zotero_Libraries::toJSON($this->libraryID)];
     $json['links'] = ['self' => ['href' => Zotero_API::getItemURI($this), 'type' => 'application/json'], 'alternate' => ['href' => Zotero_URI::getItemURI($this, true), 'type' => 'text/html']];
     if ($parent) {
         $parentItem = Zotero_Items::get($this->libraryID, $parent);
         $json['links']['up'] = ['href' => Zotero_API::getItemURI($parentItem), 'type' => 'application/json'];
     }
     // If appropriate permissions and the file is stored in ZFS, get file request link
     if ($downloadDetails) {
         $details = $downloadDetails;
         $type = $this->attachmentMIMEType;
         if ($type) {
             $json['links']['enclosure'] = ['type' => $type];
         }
         $json['links']['enclosure']['href'] = $details['url'];
         if (!empty($details['filename'])) {
             $json['links']['enclosure']['title'] = $details['filename'];
         }
         if (isset($details['size'])) {
             $json['links']['enclosure']['length'] = $details['size'];
         }
     }
     // 'meta'
     $json['meta'] = new stdClass();
     if (Zotero_Libraries::getType($this->libraryID) == 'group') {
         $createdByUserID = $this->createdByUserID;
         $lastModifiedByUserID = $this->lastModifiedByUserID;
         if ($createdByUserID) {
             $json['meta']->createdByUser = Zotero_Users::toJSON($createdByUserID);
         }
         if ($lastModifiedByUserID && $lastModifiedByUserID != $createdByUserID) {
             $json['meta']->lastModifiedByUser = Zotero_Users::toJSON($lastModifiedByUserID);
         }
     }
     if ($isRegularItem) {
         $val = $this->getCreatorSummary();
         if ($val !== '') {
             $json['meta']->creatorSummary = $val;
         }
         $val = $this->getField('date', true, true, true);
         if ($val !== '') {
             $sqlDate = Zotero_Date::multipartToSQL($val);
             if (substr($sqlDate, 0, 4) !== '0000') {
                 $json['meta']->parsedDate = Zotero_Date::sqlToISO8601($sqlDate);
             }
         }
         $json['meta']->numChildren = $numChildren;
     }
     // 'include'
     $include = $requestParams['include'];
     foreach ($include as $type) {
         if ($type == 'html') {
             $json[$type] = trim($this->toHTML());
         } else {
             if ($type == 'citation') {
                 if (isset($sharedData[$type][$this->libraryID . "/" . $this->key])) {
                     $html = $sharedData[$type][$this->libraryID . "/" . $this->key];
                 } else {
                     if ($sharedData !== null) {
                         //error_log("Citation not found in sharedData -- retrieving individually");
                     }
                     $html = Zotero_Cite::getCitationFromCiteServer($this, $requestParams);
                 }
                 $json[$type] = $html;
             } else {
                 if ($type == 'bib') {
                     if (isset($sharedData[$type][$this->libraryID . "/" . $this->key])) {
                         $html = $sharedData[$type][$this->libraryID . "/" . $this->key];
                     } else {
                         if ($sharedData !== null) {
                             //error_log("Bibliography not found in sharedData -- retrieving individually");
                         }
                         $html = Zotero_Cite::getBibliographyFromCitationServer([$this], $requestParams);
                         // Strip prolog
                         $html = preg_replace('/^<\\?xml.+\\n/', "", $html);
                         $html = trim($html);
                     }
                     $json[$type] = $html;
                 } else {
                     if ($type == 'data') {
                         $json[$type] = $this->toJSON(true, $requestParams, true);
                     } else {
                         if ($type == 'csljson') {
                             $json[$type] = $this->toCSLItem();
                         } else {
                             if (in_array($type, Zotero_Translate::$exportFormats)) {
                                 $export = Zotero_Translate::doExport([$this], $type);
                                 $json[$type] = $export['body'];
                                 unset($export);
                             }
                         }
                     }
                 }
             }
         }
     }
     // TEMP
     if ($cached) {
         $cachedStr = Zotero_Utilities::formatJSON($cached);
         $uncachedStr = Zotero_Utilities::formatJSON($json);
         if ($cachedStr != $uncachedStr) {
             error_log("Cached JSON item entry does not match");
             error_log("  Cached: " . $cachedStr);
             error_log("Uncached: " . $uncachedStr);
             //Z_Core::$MC->set($cacheKey, $uncached, 3600); // 1 hour for now
         }
     } else {
         /*Z_Core::$MC->set($cacheKey, $json, 10);
         		StatsD::timing("api.items.itemToResponseJSON.uncached", (microtime(true) - $t) * 1000);
         		StatsD::increment("memcached.items.itemToResponseJSON.miss");*/
     }
     return $json;
 }
        include $file;
    } else {
        $proc = snmp_get($device, $processor['processor_oid'], "-O Uqnv", "\"\"");
    }
    $procrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("processor-" . $processor['processor_type'] . "-" . $processor['processor_index'] . ".rrd");
    if (!is_file($procrrd)) {
        rrdtool_create($procrrd, " \\\n     DS:usage:GAUGE:600:-273:1000 ");
    }
    $proc = trim(str_replace("\"", "", $proc));
    list($proc) = preg_split("@\\ @", $proc);
    if (!$processor['processor_precision']) {
        $processor['processor_precision'] = "1";
    }
    $proc = round($proc / $processor['processor_precision'], 2);
    $graphs['processor'] = TRUE;
    echo $proc . "%\n";
    // Update StatsD/Carbon
    if ($config['statsd']['enable'] == TRUE) {
        StatsD::gauge(str_replace(".", "_", $device['hostname']) . '.' . 'processor' . '.' . $processor['processor_type'] . "-" . $processor['processor_index'], $proc);
    }
    // Update RRD
    rrdtool_update($procrrd, "N:{$proc}");
    // Update SQL State
    if (is_numeric($processor['processor_polled'])) {
        dbUpdate(array('processor_usage' => $proc, 'processor_polled' => time()), 'processors-state', '`processor_id` = ?', array($processor['processor_id']));
    } else {
        dbInsert(array('processor_id' => $processor['processor_id'], 'processor_usage' => $proc, 'processor_polled' => time()), 'processors-state');
    }
    // Check alerts
    check_entity('processor', $processor, array('processor_usage' => $proc));
}
示例#25
0
 public function logTotalRequestTime()
 {
     if (!Z_CONFIG::$STATSD_ENABLED) {
         return;
     }
     try {
         if (!empty($this->objectLibraryID)) {
             $shardID = Zotero_Shards::getByLibraryID($this->objectLibraryID);
             $shardInfo = Zotero_Shards::getShardInfo($shardID);
             $shardHostID = (int) $shardInfo['shardHostID'];
             StatsD::timing("api.request.total_by_shard.{$shardHostID}", (microtime(true) - $this->startTime) * 1000, 0.25);
         }
     } catch (Exception $e) {
         error_log("WARNING: " . $e);
     }
     StatsD::timing("api.memcached", Z_Core::$MC->requestTime * 1000, 0.25);
     StatsD::timing("api.request.total", (microtime(true) - $this->startTime) * 1000, 0.25);
 }
示例#26
0
 /**
  * @todo Implement testGaugeStats().
  */
 public function testGaugeStats()
 {
     $this->statsd->gauge("test.gaugeStat", "5", "1");
 }
示例#27
0
                     $mempool['total'] = 100;
                     $mempool['used'] = $mempool['perc'];
                 } else {
                     // Hrrmm.. it looks like empty snmp walk
                     continue;
                 }
             }
         }
     }
 }
 $mempool['free'] = $mempool['total'] - $mempool['used'];
 $hc = $mempool['mempool_hc'] ? ' (HC)' : '';
 // Update StatsD/Carbon
 if ($config['statsd']['enable'] == TRUE) {
     StatsD::gauge(str_replace(".", "_", $device['hostname']) . '.' . 'mempool' . '.' . $mempool['mempool_mib'] . "." . $mempool['mempool_index'] . ".used", $mempool['used']);
     StatsD::gauge(str_replace(".", "_", $device['hostname']) . '.' . 'mempool' . '.' . $mempool['mempool_mib'] . "." . $mempool['mempool_index'] . ".free", $mempool['free']);
 }
 rrdtool_update_ng($device, 'mempool', array('used' => $mempool['used'], 'free' => $mempool['free']), $mempool['mempool_mib'] . "-" . $mempool['mempool_index']);
 if (!is_numeric($mempool['mempool_polled'])) {
     dbInsert(array('mempool_id' => $mempool['mempool_id']), 'mempools-state');
 }
 $mempool['state'] = array('mempool_polled' => time(), 'mempool_used' => $mempool['used'], 'mempool_perc' => $mempool['perc'], 'mempool_free' => $mempool['free'], 'mempool_total' => $mempool['total']);
 dbUpdate($mempool['state'], 'mempools-state', '`mempool_id` = ?', array($mempool['mempool_id']));
 $graphs['mempool'] = TRUE;
 check_entity('mempool', $mempool, array('mempool_perc' => $mempool['perc'], 'mempool_free' => $mempool['free'], 'mempool_used' => $mempool['used']));
 //  print_message("Mempool ". $mempool['mempool_descr'] . ': '.$mempool['perc'].'%%'.$hc);
 $table_row = array();
 $table_row[] = $mempool['mempool_descr'];
 $table_row[] = $mempool['mempool_mib'];
 $table_row[] = $mempool['mempool_index'];
 $table_row[] = formatStorage($mempool['total']);
示例#28
0
 public function clear()
 {
     $this->sessionCheck();
     if (Zotero_Sync::userIsReadLocked($this->userID) || Zotero_Sync::userIsWriteLocked($this->userID)) {
         $message = "You cannot reset server data while one of your libraries " . "is locked for syncing. Please wait for all related syncs to complete.";
         $this->error(400, 'SYNC_LOCKED', $message);
     }
     StatsD::increment("sync.clear");
     Zotero_Users::clearAllData($this->userID);
     $this->responseXML->addChild('cleared');
     $this->end();
 }
示例#29
0
 public static function multiResponse($options, $overrideFormat = false)
 {
     $format = $overrideFormat ? $overrideFormat : $options['requestParams']['format'];
     if (empty($options['results'])) {
         $options['results'] = ['results' => [], 'total' => 0];
     }
     if ($options['results'] && isset($options['results']['results'])) {
         $totalResults = $options['results']['total'];
         $options['results'] = $options['results']['results'];
         if ($options['requestParams']['v'] >= 3) {
             header("Total-Results: {$totalResults}");
         }
     }
     switch ($format) {
         case 'atom':
         case 'csljson':
         case 'json':
         case 'keys':
         case 'versions':
             $link = Zotero_API::buildLinkHeader($options['action'], $options['uri'], $totalResults, $options['requestParams']);
             if ($link) {
                 header($link);
             }
             break;
     }
     if (!empty($options['head'])) {
         return;
     }
     switch ($format) {
         case 'atom':
             $t = microtime(true);
             $response = Zotero_Atom::createAtomFeed($options['action'], $options['title'], $options['uri'], $options['results'], $totalResults, $options['requestParams'], $options['permissions'], isset($options['fixedValues']) ? $options['fixedValues'] : null);
             StatsD::timing("api." . $options['action'] . ".multiple.createAtomFeed." . implode("-", $options['requestParams']['content']), (microtime(true) - $t) * 1000);
             return $response;
         case 'csljson':
             $json = Zotero_Cite::getJSONFromItems($options['results'], true);
             echo Zotero_Utilities::formatJSON($json);
             break;
         case 'json':
             echo Zotero_API::createJSONResponse($options['results'], $options['requestParams'], $options['permissions']);
             break;
         case 'keys':
             echo implode("\n", $options['results']) . "\n";
             break;
         case 'versions':
             if (!empty($options['results'])) {
                 echo Zotero_Utilities::formatJSON($options['results']);
             } else {
                 echo Zotero_Utilities::formatJSON(new stdClass());
             }
             break;
         case 'writereport':
             echo Zotero_Utilities::formatJSON($options['results']);
             break;
         default:
             throw new Exception("Unexpected format '" . $options['requestParams']['format'] . "'");
     }
 }
示例#30
0
                $stats['ipSystemStatsOutForwDatagrams'] = $stats['ipSystemStatsHCOutForwDatagrams'];
            }
            unset($snmpstring, $rrdupdate, $snmpdata, $snmpdata_cmd, $rrd_create);
            $rrdfile = "ipSystemStats-{$af}.rrd";
            $rrdupdate = "N";
            foreach ($oids as $oid) {
                $oid_ds = str_replace("ipSystemStats", "", $oid);
                $oid_ds = truncate($oid_ds, 19, '');
                $rrd_create .= " DS:{$oid_ds}:COUNTER:600:U:100000000000";
                if (strstr($stats[$oid], "No") || strstr($stats[$oid], "d") || strstr($stats[$oid], "s")) {
                    $stats[$oid] = "0";
                }
                $rrdupdate .= ":" . $stats[$oid];
                // Update StatsD/Carbon
                if ($config['statsd']['enable'] == TRUE && !strpos($oid, "HC")) {
                    StatsD::gauge(str_replace(".", "_", $device['hostname']) . '.' . 'system' . '.' . $oid, $stats[$oid]);
                }
            }
            rrdtool_create($device, $rrdfile, $rrd_create);
            rrdtool_update($device, $rrdfile, $rrdupdate);
            unset($rrdupdate, $rrd_create);
            // FIXME per-AF?
            $graphs['ipsystemstats_' . $af] = TRUE;
            $graphs['ipsystemstats_' . $af . '_frag'] = TRUE;
            $show_graphs[] = 'ipsystemstats_' . $af;
            $show_graphs[] = 'ipsystemstats_' . $af . '_frag';
        }
        echo PHP_EOL;
        print_cli_data("Graphs", implode($show_graphs, " "), 2);
    }
}