<?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');
    }

    $dataDia = date('Y-m-d', strtotime('-1 days'));
    $curl->setUrl('/relatorio/sinistro/relatoriodiariocadastrosperitos');
    $curl->doRequest('POST', ['tipo' => 'excel', 'origemCurl' => true]);

    $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";
}