getStatus() public method

public getStatus ( $cached = false )
Ejemplo n.º 1
0
 /**
  * @param DBServer $dbServer
  * @param bool $cached check only cached information
  * @param int $timeout
  * @return array|NULL
  */
 public function getServerStatus(DBServer $dbServer, $cached = true, $timeout = 0)
 {
     if ($dbServer->status == SERVER_STATUS::RUNNING && ($dbServer->IsSupported('0.8') && $dbServer->osType == 'linux' || $dbServer->IsSupported('0.19') && $dbServer->osType == 'windows')) {
         if ($cached && !$dbServer->IsSupported('2.7.7')) {
             return ['status' => 'statusNoCache', 'error' => "<span style='color:gray;'>Scalarizr is checking actual status</span>"];
         }
         try {
             $port = $dbServer->GetProperty(SERVER_PROPERTIES::SZR_UPDC_PORT);
             if (!$port) {
                 $port = 8008;
             }
             if (!$timeout) {
                 $timeout = \Scalr::config('scalr.system.instances_connection_timeout');
             }
             $updateClient = new Scalr_Net_Scalarizr_UpdateClient($dbServer, $port, $timeout);
             $scalarizr = $updateClient->getStatus($cached);
             try {
                 if ($dbServer->farmRoleId != 0) {
                     $scheduledOn = $dbServer->GetFarmRoleObject()->GetSetting('scheduled_on');
                 }
             } catch (Exception $e) {
             }
             $nextUpdate = null;
             if ($scalarizr->candidate && $scalarizr->installed != $scalarizr->candidate) {
                 $nextUpdate = ['candidate' => htmlspecialchars($scalarizr->candidate), 'scheduledOn' => $scheduledOn ? Scalr_Util_DateTime::convertTzFromUTC($scheduledOn) : null];
             }
             return ['status' => htmlspecialchars($scalarizr->service_status), 'version' => htmlspecialchars($scalarizr->installed), 'candidate' => htmlspecialchars($scalarizr->candidate), 'repository' => ucfirst(htmlspecialchars($scalarizr->repository)), 'lastUpdate' => ['date' => $scalarizr->executed_at ? Scalr_Util_DateTime::convertTzFromUTC($scalarizr->executed_at) : "", 'error' => nl2br(htmlspecialchars($scalarizr->error))], 'nextUpdate' => $nextUpdate, 'fullInfo' => $scalarizr];
         } catch (Exception $e) {
             if (stristr($e->getMessage(), "Method not found")) {
                 return ['status' => 'statusNotAvailable', 'error' => "<span style='color:red;'>Scalarizr status is not available, because scalr-upd-client installed on this server is too old.</span>"];
             } else {
                 return ['status' => 'statusNotAvailable', 'error' => "<span style='color:red;'>Scalarizr status is not available: {$e->getMessage()}</span>"];
             }
         }
     }
 }
Ejemplo n.º 2
0
 public function extendedInfoAction()
 {
     if (!$this->getParam('serverId')) {
         throw new Exception(_('Server not found'));
     }
     $dbServer = DBServer::LoadByID($this->getParam('serverId'));
     $this->user->getPermissions()->validate($dbServer);
     $info = PlatformFactory::NewPlatform($dbServer->platform)->GetServerExtendedInformation($dbServer);
     $form = array(array('xtype' => 'fieldcontainer', 'layout' => 'hbox', 'hideLabel' => true, 'items' => array(array('xtype' => 'fieldset', 'title' => 'General', 'height' => 218, 'flex' => 1, 'margin' => '0 3 0 0', 'labelWidth' => 240, 'items' => array(array('xtype' => 'displayfield', 'fieldLabel' => 'Server ID', 'width' => 380, 'value' => $dbServer->serverId), array('xtype' => 'displayfield', 'fieldLabel' => 'Platform', 'value' => $dbServer->platform), array('xtype' => 'displayfield', 'fieldLabel' => 'Remote IP', 'value' => $dbServer->remoteIp ? $dbServer->remoteIp : ''), array('xtype' => 'displayfield', 'fieldLabel' => 'Local IP', 'value' => $dbServer->localIp ? $dbServer->localIp : ''), array('xtype' => 'displayfield', 'fieldLabel' => 'Status', 'value' => $dbServer->status), array('xtype' => 'displayfield', 'fieldLabel' => 'Index', 'value' => $dbServer->index), array('xtype' => 'displayfield', 'fieldLabel' => 'Added at', 'value' => Scalr_Util_DateTime::convertTz($dbServer->dateAdded)))))));
     /***** Scalr agent *****/
     if ($dbServer->status == SERVER_STATUS::RUNNING) {
         try {
             $updateClient = new Scalr_Net_Scalarizr_UpdateClient($dbServer);
             $status = $updateClient->getStatus();
         } catch (Exception $e) {
             $oldUpdClient = stristr($e->getMessage(), "Method not found");
             $error = $e->getMessage();
         }
         if ($status) {
             $items = array(array('xtype' => 'displayfield', 'fieldLabel' => 'Scalarizr status', 'value' => $status->service_status == 'running' ? "<span style='color:green;'>Running</span>" : "<span style='color:red;'>" . ucfirst($status->service_status) . "</span>"), array('xtype' => 'displayfield', 'fieldLabel' => 'Version', 'value' => $status->installed), array('xtype' => 'displayfield', 'fieldLabel' => 'Repository', 'value' => ucfirst($status->repository)), array('xtype' => 'displayfield', 'fieldLabel' => 'Last update', 'value' => Scalr_Util_DateTime::convertTz($status->executed_at)), array('xtype' => 'displayfield', 'fieldLabel' => 'Last update status', 'value' => $status->error ? "<span style='color:red;'>Error: " . nl2br($status->error) . "</span>" : "<span style='color:green;'>Success</span>"), array('xtype' => 'displayfield', 'fieldLabel' => 'Next update', 'value' => $status->installed != $status->candidate ? "Update to <b>{$status->candidate}</b> scheduled on <b>" . Scalr_Util_DateTime::convertTz($status->scheduled_on) . "</b>" : "Scalarizr is up to date"), array('xtype' => 'displayfield', 'fieldLabel' => 'Schedule', 'value' => $status->schedule), array('xtype' => 'fieldcontainer', 'layout' => 'hbox', 'hideLabel' => true, 'items' => array(array('xtype' => 'button', 'itemId' => 'updateSzrBtn', 'text' => 'Update scalarizr now', 'disabled' => $status->installed == $status->candidate, 'flex' => 1, 'margin' => $this->getParam('beta') == 1 ? '0 3 0 0' : '0 0 0 0'), array('xtype' => 'button', 'itemId' => 'restartSzrBtn', 'text' => 'Restart scalarizr', 'flex' => 1))));
         } else {
             if ($oldUpdClient) {
                 $items = array(array('xtype' => 'button', 'itemId' => 'upgradeUpdClientBtn', 'text' => 'Upgrade scalarizr upd-client', 'flex' => 1));
             } else {
                 $items = array(array('xtype' => 'displayfield', 'hideLabel' => true, 'value' => "<span style='color:red;'>Scalarizr status is not available: {$error}</span>"));
             }
         }
         $form[0]['items'][] = array('xtype' => 'fieldset', 'labelWidth' => 240, 'flex' => 1, 'title' => 'Scalr agent status', 'items' => $items);
     }
     /***** Scalr agent *****/
     $it = array();
     if (is_array($info) && count($info)) {
         foreach ($info as $name => $value) {
             $it[] = array('xtype' => 'displayfield', 'fieldLabel' => $name, 'value' => $value);
         }
     } else {
         $it[] = array('xtype' => 'displayfield', 'hideLabel' => true, 'value' => 'Platform specific details not available for this server');
     }
     $form[] = array('xtype' => 'fieldset', 'labelWidth' => 240, 'title' => 'Platform specific details', 'collapsible' => true, 'collapsed' => false, 'items' => $it);
     /*
     
     <tr>
     	<td width="20%">CloudWatch monitoring:</td>
     	<td>{if $info->instancesSet->item->monitoring->state == 'enabled'}
     			<a href="/aws_cw_monitor.php?ObjectId={$info->instancesSet->item->instanceId}&Object=InstanceId&NameSpace=AWS/EC2">{$info->instancesSet->item->monitoring->state}</a>
     			&nbsp;(<a href="aws_ec2_cw_manage.php?action=Disable&iid={$info->instancesSet->item->instanceId}&region={$smarty.request.region}">Disable</a>)
     		{else}
     			{$info->instancesSet->item->monitoring->state}
     			&nbsp;(<a href="aws_ec2_cw_manage.php?action=Enable&iid={$info->instancesSet->item->instanceId}&region={$smarty.request.region}">Enable</a>)
     		{/if}
     	</td>
     </tr>
     -->
     {include file="inc/intable_footer.tpl" color="Gray"}
     */
     if (count($dbServer->GetAllProperties())) {
         $it = array();
         foreach ($dbServer->GetAllProperties() as $name => $value) {
             $it[] = array('xtype' => 'displayfield', 'fieldLabel' => $name, 'value' => $value);
         }
         $form[] = array('xtype' => 'fieldset', 'title' => 'Scalr internal server properties', 'collapsible' => true, 'collapsed' => true, 'labelWidth' => 220, 'items' => $it);
     }
     if (!$dbServer->IsSupported('0.5')) {
         $authKey = $dbServer->GetKey();
         if (!$authKey) {
             $authKey = Scalr::GenerateRandomKey(40);
             $dbServer->SetProperty(SERVER_PROPERTIES::SZR_KEY, $authKey);
         }
         $dbServer->SetProperty(SERVER_PROPERTIES::SZR_KEY_TYPE, SZR_KEY_TYPE::PERMANENT);
         $form[] = array('xtype' => 'fieldset', 'title' => 'Upgrade from ami-scripts to scalarizr', 'labelWidth' => 220, 'items' => array('xtype' => 'textarea', 'hideLabel' => true, 'readOnly' => true, 'anchor' => '-20', 'value' => sprintf("wget " . CONFIG::$HTTP_PROTO . "://" . CONFIG::$EVENTHANDLER_URL . "/storage/scripts/amiscripts-to-scalarizr.py && python amiscripts-to-scalarizr.py -s %s -k %s -o queryenv-url=%s -o messaging_p2p.producer_url=%s", $dbServer->serverId, $authKey, CONFIG::$HTTP_PROTO . "://" . CONFIG::$EVENTHANDLER_URL . "/query-env", CONFIG::$HTTP_PROTO . "://" . CONFIG::$EVENTHANDLER_URL . "/messaging")));
     }
     $this->response->page('ui/servers/extendedinfo.js', $form);
 }
Ejemplo n.º 3
0
 public function dashboardAction()
 {
     if (!$this->request->isAllowed(Acl::RESOURCE_FARMS_SERVERS) && !$this->request->isAllowed(Acl::RESOURCE_FARMS_ROLES, Acl::PERM_FARMS_ROLES_CREATE)) {
         throw new Scalr_Exception_InsufficientPermissions();
     }
     if (!$this->getParam('serverId')) {
         throw new Exception(_('Server not found'));
     }
     $dbServer = DBServer::LoadByID($this->getParam('serverId'));
     $this->user->getPermissions()->validate($dbServer);
     $data = array();
     $info = PlatformFactory::NewPlatform($dbServer->platform)->GetServerExtendedInformation($dbServer);
     if (is_array($info) && count($info)) {
         $data['cloudProperties'] = $info;
     }
     try {
         $dbRole = $dbServer->GetFarmRoleObject()->GetRoleObject();
     } catch (Exception $e) {
     }
     $r_dns = $this->db->GetOne("SELECT value FROM farm_role_settings WHERE farm_roleid=? AND `name`=? LIMIT 1", array($dbServer->farmRoleId, DBFarmRole::SETTING_EXCLUDE_FROM_DNS));
     $data['general'] = array('server_id' => $dbServer->serverId, 'farm_id' => $dbServer->farmId, 'farm_role_id' => $dbServer->farmRoleId, 'role_id' => isset($dbRole) ? $dbRole->id : null, 'platform' => $dbServer->platform, 'cloud_location' => $dbServer->GetCloudLocation(), 'role' => array('name' => isset($dbRole) ? $dbRole->name : 'unknown', 'platform' => $dbServer->platform), 'os' => array('title' => isset($dbRole) ? $dbRole->os : 'unknown', 'family' => isset($dbRole) ? $dbRole->osFamily : 'unknown'), 'behaviors' => isset($dbRole) ? $dbRole->getBehaviors() : array(), 'status' => $dbServer->status, 'index' => $dbServer->index, 'local_ip' => $dbServer->localIp, 'remote_ip' => $dbServer->remoteIp, 'instType' => PlatformFactory::NewPlatform($dbServer->platform)->GetServerFlavor($dbServer), 'addedDate' => Scalr_Util_DateTime::convertTz($dbServer->dateAdded), 'excluded_from_dns' => !$dbServer->GetProperty(SERVER_PROPERTIES::EXCLUDE_FROM_DNS) && !$r_dns ? false : true, 'is_locked' => $dbServer->GetProperty(EC2_SERVER_PROPERTIES::IS_LOCKED) ? 1 : 0, 'cloud_server_id' => $dbServer->GetCloudServerID());
     if ($dbServer->status == SERVER_STATUS::RUNNING) {
         $rebooting = $this->db->GetOne("SELECT value FROM server_properties WHERE server_id=? AND `name`=? LIMIT 1", array($dbServer->serverId, SERVER_PROPERTIES::REBOOTING));
         if ($rebooting) {
             $data['general']['status'] = "Rebooting";
         }
         $subStatus = $dbServer->GetProperty(SERVER_PROPERTIES::SUB_STATUS);
         if ($subStatus) {
             $data['general']['status'] = ucfirst($subStatus);
         }
     }
     if ($dbServer->status == SERVER_STATUS::RUNNING && $dbServer->GetProperty(SERVER_PROPERTIES::SUB_STATUS) != 'stopped' && ($dbServer->IsSupported('0.8') && $dbServer->osType == 'linux' || $dbServer->IsSupported('0.19') && $dbServer->osType == 'windows')) {
         try {
             $port = $dbServer->GetProperty(SERVER_PROPERTIES::SZR_UPDC_PORT);
             if (!$port) {
                 $port = 8008;
             }
             $updateClient = new Scalr_Net_Scalarizr_UpdateClient($dbServer, $port, \Scalr::config('scalr.system.instances_connection_timeout'));
             $scalarizr = $updateClient->getStatus();
         } catch (Exception $e) {
             $oldUpdClient = stristr($e->getMessage(), "Method not found");
             $error = $e->getMessage();
         }
         if ($scalarizr) {
             $data['scalarizr'] = array('status' => $scalarizr->service_status, 'version' => $scalarizr->installed, 'candidate' => $scalarizr->candidate, 'repository' => ucfirst($scalarizr->repository), 'lastUpdate' => array('date' => $scalarizr->executed_at ? Scalr_Util_DateTime::convertTz($scalarizr->executed_at) : "", 'error' => nl2br($scalarizr->error)), 'nextUpdate' => $scalarizr->installed != $scalarizr->candidate ? "Update to <b>{$scalarizr->candidate}</b> scheduled on <b>" . Scalr_Util_DateTime::convertTz($scalarizr->scheduled_on) . "</b>" : "Scalarizr is up to date", 'fullInfo' => $scalarizr);
         } else {
             if ($oldUpdClient) {
                 $data['scalarizr'] = array('status' => 'upgradeUpdClient');
             } else {
                 $data['scalarizr'] = array('status' => 'statusNotAvailable', 'error' => "<span style='color:red;'>Scalarizr status is not available: {$error}</span>");
             }
         }
     }
     $internalProperties = $dbServer->GetAllProperties();
     if (!empty($internalProperties)) {
         $data['internalProperties'] = $internalProperties;
     }
     if (!$dbServer->IsSupported('0.5')) {
         $baseurl = $this->getContainer()->config('scalr.endpoint.scheme') . "://" . $this->getContainer()->config('scalr.endpoint.host');
         $authKey = $dbServer->GetKey();
         if (!$authKey) {
             $authKey = Scalr::GenerateRandomKey(40);
             $dbServer->SetProperty(SERVER_PROPERTIES::SZR_KEY, $authKey);
         }
         $dbServer->SetProperty(SERVER_PROPERTIES::SZR_KEY_TYPE, SZR_KEY_TYPE::PERMANENT);
         $data['updateAmiToScalarizr'] = sprintf("wget " . $baseurl . "/storage/scripts/amiscripts-to-scalarizr.py && python amiscripts-to-scalarizr.py -s %s -k %s -o queryenv-url=%s -o messaging_p2p.producer_url=%s", $dbServer->serverId, $authKey, $baseurl . "/query-env", $baseurl . "/messaging");
     }
     $this->response->page('ui/servers/dashboard.js', $data, array('ui/servers/actionsmenu.js', 'ui/monitoring/window.js'));
 }