protected function execute(InputInterface $input, OutputInterface $output) { $logger = $this->getService('logger'); $account_name = $input->getOption('account-name'); try { $client = new GClient($input->getArgument('server'), array('request.options' => array('auth' => array($input->getArgument('username'), $input->getArgument('password'))))); $agent = new Agent($logger, $client, $account_name); $agent->setFacter(new MultiFacterFacter(array(new SystemFacter(), new ArrayFacter($this->getCustomFacts($input, 'system')))), Agent::SYSTEM); $agent->setFacter(new MultiFacterFacter(array(new SugarFacter($this->getService('sugarcrm.application'), $this->getService('sugarcrm.pdo')), new ArrayFacter($this->getCustomFacts($input, 'sugarcrm')))), Agent::SUGARCRM); $agent->sendAll(); $output->writeln('Successfuly sent report to inventory server.'); } catch (RequestException $e) { $logger->error('An error occured while contacting the inventory server.'); $logger->error($e->getMessage()); return ExitCode::EXIT_INVENTORY_ERROR; } catch (SugarException $e) { $logger->error('An error occured with the sugar application.'); $logger->error($e->getMessage()); return ExitCode::EXIT_UNKNOWN_SUGAR_ERROR; } }
public function testSendSugarInstance() { $name = $this->instance_id; $client = $this->getClient(); $agent = new Agent(new NullLogger(), $client, $this->account_name); try { $client->deleteSugarInstance(array('instance_id' => $this->instance_id)); } catch (ClientErrorResponseException $e) { } $history = $this->getHistory($client); $agent->setFacter(new ArrayFacter(array('instance_id' => $name, 'flavor' => 'PRO')), Agent::SUGARCRM); // Should POST $agent->sendSugarInstance(); $this->assertEquals('POST', $history->getLastRequest()->getMethod()); // Should PUT $account_id = $agent->getAccountId($this->account_name); $this->assertInternalType('integer', $account_id); $server_id = $agent->getServerId($this->server_fqdn); $this->assertInternalType('integer', $server_id); $agent->sendSugarInstance($server_id, $account_id); $this->assertEquals('PUT', $history->getLastRequest()->getMethod()); // Test full send $agent->setFacter(new ArrayFacter(array('fqdn' => $this->server_fqdn)), Agent::SYSTEM); $agent->sendAll(); }