-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
66 lines (46 loc) · 1.71 KB
/
Copy pathmain.cpp
File metadata and controls
66 lines (46 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "Lib/ZabbixApiClient.hpp"
#include "Lib/GetProgramOptions.hpp"
#include "Lib/PrepareRequestFromOpt.hpp"
#include "Lib/PTreePrinter.hpp"
#include <vector>
namespace beast = boost::beast;
namespace http = beast::http;
namespace net = boost::asio;
using tcp = boost::asio::ip::tcp;
namespace pt = boost::property_tree;
int main(int argc, char** argv)
{
try
{
ProgramOptions options;
GetProgramOptions::getOptions(argc, argv, options);
//std::cout << options << std::endl;
ZabbixApiClient client(options.apiConfig.url, options.apiConfig.apiPath, \
options.apiConfig.username, options.apiConfig.password);
pt::ptree body;
if (!options.jsonFile.empty())
{
std::ifstream jsonfile(options.jsonFile.c_str());
if (!jsonfile)
throw std::runtime_error("Could not open file: " + options.jsonFile);
pt::read_json(jsonfile, body);
}
else
body = prepareJsonBody(options.reqConfig);
//pt::write_json(std::cout, body);
auto request = client.prepareRequest(http::string_to_verb(options.reqConfig.httpMethod), \
options.reqConfig.method, body);
//std::cout << request << std::endl << std::endl << std::endl << std::endl;
auto response = client.sendRequest(request);
std::vector<std::string> &toPrint = (options.outputConfig.keyToPrint.empty() ? options.reqConfig.outputs : options.outputConfig.keyToPrint); //burada eğer dizi boş ise tamamını bastırmalı.
if (options.outputConfig.outputFormat == "json")
PTreePrinter::printStringToJson(response);
else if (options.outputConfig.outputFormat == "csv")
PTreePrinter::printJsonToCsv(response, toPrint);
return 0;
}
catch(std::exception& e)
{
std::cout << "ERROR: " << e.what() << std::endl;
}
}