-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtweetproc.c
40 lines (36 loc) · 917 Bytes
/
tweetproc.c
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
/*
Main file to be compiled and run.
tweetproc sends hourly statistic updates about the computer it is being run on
also checks if the cpu temp is over a threshold
*/
#include "postFunctions.h"
void checkThreshold(char *temp){
char *cpustr = strstr(temp, "+") + 1;
char warning[POST_SIZE];
int i=0;
while(cpustr[i]!= '.'){
i++;
}
cpustr[i] = NULL;
int thres = (int)strtol(cpustr, (char**)NULL, 10);
if(thres > 30){
printf("In warning\n\n");
snprintf(warning, POST_SIZE, "Warning: CPU temp over threshold (Current: %dC)", thres);
post(warning);
}
}
int main(void)
{
while(1){
char *uptime = parseUptime();
char *load = parseLoadtime();
char *CPU = parseTemp();
char *IP = parseIP();
checkThreshold(CPU);
char postit[POST_SIZE];
snprintf(postit, POST_SIZE, "Up: %s, Load: %s, CPU: %s, IP: %s", uptime, load, CPU, IP);
post(postit);
sleep(90);
}
return 0;
}