-
Clara Daia Hilgenberg Daru authoredClara Daia Hilgenberg Daru authored
post.cpp 3.11 KiB
/* Copyright (C) 2004-2016 Centro de Computacao Cientifica e Software Livre
* Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
*
* This file is part of simmc-agent
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*/
#include "agent/post.h"
/*******************************
* INVENTORY *
*******************************/
int send_inventory() {
Json::Value inventory = get_inventory();
Json::FastWriter fastWriter;
#ifdef PRINT_JSON
Json::StyledWriter styledWriter;
if (!inventory.isNull())
std::cout << styledWriter.write(inventory);
else
std::cout << "Empty inventory object" << std::endl;
#endif
auto p = cpr::Post(cpr::Url{base_url + "/api/v1/collect"},
cpr::Parameters{{"type", "inventory"}},
cpr::Body{fastWriter.write(inventory)},
cpr::Header{{"content-type", "application/json"}});
if (p.status_code == 200) {
return 1;
}
return 0;
}
/***************************************
* NETWORK BANDWIDTH *
***************************************/
int send_net_bandwidth() {
Json::Value net;
Json::FastWriter fastWriter;
#ifdef PRINT_JSON
Json::StyledWriter styledWriter;
if (!net.isNull())
std::cout << styledWriter.write(net);
else
std::cout << "Empty network_bandwidth object" << std::endl;
#endif
auto p = cpr::Post(cpr::Url{base_url + "/api/v1/collect"},
cpr::Parameters{{"type", "network_bandwidth"}},
cpr::Body{fastWriter.write(net)},
cpr::Header{{"content-type", "application/json"}});
if (p.status_code == 200) {
return 1;
}
return 0;
}
/**********************************
* USER HISTORY *
**********************************/
int send_user_history() {
Json::Value u_h;
Json::FastWriter fastWriter;
#ifdef PRINT_JSON
Json::StyledWriter styledWriter;
if (!u_h.isNull())
std::cout << styledWriter.write(u_h);
else
std::cout << "Empty user_history object" << std::endl;
#endif
auto p = cpr::Post(cpr::Url{base_url + "/api/v1/collect"},
cpr::Parameters{{"type", "user_history"}},
cpr::Body{fastWriter.write(u_h)},
cpr::Header{{"content-type", "application/json"}});
if (p.status_code == 200) {
return 1;
}
return 0;
}