/[projects]/smsdaemon/plugins/HostStatusPlugin.cpp
ViewVC logotype

Contents of /smsdaemon/plugins/HostStatusPlugin.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 196 - (show annotations) (download)
Thu Dec 18 06:53:29 2008 UTC (15 years, 5 months ago) by torben
File size: 1130 byte(s)
Make pretty

astyle -t -b -N

1 #include "HostStatusPlugin.h"
2 #include "ISmsTransceiver.h"
3 #include "Sms.h"
4 #include "Util.h"
5
6 #include <vector>
7 #include <sstream>
8 #include <iostream>
9
10 using namespace std;
11
12 HostStatusPlugin::HostStatusPlugin()
13 : 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)
35 {
36 string message;
37 string out;
38
39 Util::my_system("hostname", &out);
40 message += out;
41
42 Util::my_system("uptime", &out);
43 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);
49 message += out;
50
51 modem.SendSms(sms.GetSender(), message, true);
52
53 }

  ViewVC Help
Powered by ViewVC 1.1.20