3 |
#include "Sms.h" |
#include "Sms.h" |
4 |
#include "Util.h" |
#include "Util.h" |
5 |
|
|
6 |
|
#include <vector> |
7 |
|
#include <sstream> |
8 |
|
#include <iostream> |
9 |
|
|
10 |
using namespace std; |
using namespace std; |
11 |
|
|
12 |
HostStatusPlugin::HostStatusPlugin() |
HostStatusPlugin::HostStatusPlugin() |
13 |
: Plugin("hoststatus", "returns an sms with host server status") |
: Plugin("hoststatus", "returns an sms with host server status") |
14 |
{ |
{ |
15 |
} |
} |
16 |
|
|
17 |
|
string ParseMemory(string mem) |
18 |
|
{ |
19 |
|
stringstream out; |
20 |
|
|
21 |
|
vector<string> lines = Util::str_split(mem,"\n"); |
22 |
|
vector<string> line2 = Util::str_split( lines[1] ); |
23 |
|
vector<string> line3 = Util::str_split( lines[2] ); |
24 |
|
|
25 |
|
out << "Mem." << endl; |
26 |
|
out << "Applications: " << line3[2] << "mb\n" ; |
27 |
|
out << "Buffers: " << line2[5] << "mb\n" ; |
28 |
|
out << "Cache: " << line2[6] << "mb\n"; |
29 |
|
out << "Free: " << line2[3] << "mb\n\n"; |
30 |
|
|
31 |
|
return out.str(); |
32 |
|
} |
33 |
|
|
34 |
void HostStatusPlugin::Execute(ISmsTransceiver& modem, SMS& sms) |
void HostStatusPlugin::Execute(ISmsTransceiver& modem, SMS& sms) |
35 |
{ |
{ |
36 |
string message; |
string message; |
42 |
Util::my_system("uptime", &out); |
Util::my_system("uptime", &out); |
43 |
message += out; |
message += out; |
44 |
|
|
45 |
|
Util::my_system("free -m",&out); |
46 |
|
message += ParseMemory(out); |
47 |
|
|
48 |
Util::my_system("df -h | grep dev | awk '{ print $6 \" \" $5}'", &out); |
Util::my_system("df -h | grep dev | awk '{ print $6 \" \" $5}'", &out); |
49 |
message += out; |
message += out; |
50 |
|
|
51 |
modem.SendSms(sms.GetSender(), message, true); |
modem.SendSms(sms.GetSender(), message, true); |
52 |
|
|
53 |
} |
} |