forked from jackburton79/ocs-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAgent.cpp
49 lines (37 loc) · 861 Bytes
/
Agent.cpp
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
/*
* Agent.cpp
*
* Created on: 11/lug/2013
* Author: stefano
*/
#include "Agent.h"
#include "Configuration.h"
#include "Inventory.h"
#include <iostream>
#include <unistd.h>
Agent::Agent()
{
if (geteuid() != 0) {
throw std::string("This program needs to be run as root");
}
}
Agent::~Agent()
{
}
void
Agent::Run()
{
Configuration* config = Configuration::Get();
Inventory inventory;
if (!inventory.Initialize(config->DeviceID().c_str()))
throw "Cannot initialize Inventory";
if (inventory.Build(config->DeviceID().c_str())) {
if (!config->LocalInventory()) {
if (inventory.Send(config->ServerURL().c_str()))
return;
std::cerr << "Cannot send inventory. Will try to save it locally." << std::endl;
}
if (!inventory.Save(config->DeviceID().c_str()))
std::cerr << "Cannot save inventory file." << std::endl;
}
}