<?php
require_once('Agro_Curl.php');

preg_match("/^agrobr-app02\.*/", gethostname(), $matches);

$now = new \Datetime;
try {
    if (count($matches) > 0) {
        $curl = new Agro_Curl('agronet.agrobrasilseguros.com.br', 'https');
    } else {
        $curl = new Agro_Curl('localhost', 'http');
    }

    $curl->setUrl('/relatorio/comercial/capacidadecomercialemail');

    $post = array(
      'tipo'                   => 'excel',
      'id_estado'              => 0,
      'id_validacao'           => '',
      'filtrarCapacidadeEmail' => true
    );

    $curl->doRequest('POST', $post);

    $result = $curl->getResult();
    $result = $now->format('Y-m-d H:i:s') . ": " . $result->message . " \n";
} catch (\Exception $e) {
    $result = $now->format('Y-m-d H:i:s') . ': ' . $e->getMessage() . '. ' . $e->getTraceAsString() . "\n";
}