1 /*----------------------------------------------------------------------------*/
2 /* Xymon message daemon. */
3 /* */
4 /* Client backend module for OpenBSD */
5 /* */
6 /* Copyright (C) 2005-2011 Henrik Storner <henrik@hswn.dk> */
7 /* */
8 /* This program is released under the GNU General Public License (GPL), */
9 /* version 2. See the file "COPYING" for details. */
10 /* */
11 /*----------------------------------------------------------------------------*/
12
13 static char openbsd_rcsid[] = "$Id: openbsd.c 7886 2016-02-02 20:16:19Z jccleaver $";
14
handle_openbsd_client(char * hostname,char * clienttype,enum ostype_t os,void * hinfo,char * sender,time_t timestamp,char * clientdata)15 void handle_openbsd_client(char *hostname, char *clienttype, enum ostype_t os,
16 void *hinfo, char *sender, time_t timestamp,
17 char *clientdata)
18 {
19 char *timestr;
20 char *uptimestr;
21 char *clockstr;
22 char *msgcachestr;
23 char *whostr;
24 char *psstr;
25 char *topstr;
26 char *dfstr;
27 char *inodestr;
28 char *meminfostr;
29 char *msgsstr;
30 char *netstatstr;
31 char *ifstatstr;
32 char *portsstr;
33 char *vmstatstr;
34
35 char *p;
36 char fromline[1024];
37
38 sprintf(fromline, "\nStatus message received from %s\n", sender);
39
40 splitmsg(clientdata);
41
42 timestr = getdata("date");
43 uptimestr = getdata("uptime");
44 clockstr = getdata("clock");
45 msgcachestr = getdata("msgcache");
46 whostr = getdata("who");
47 psstr = getdata("ps");
48 topstr = getdata("top");
49 dfstr = getdata("df");
50 inodestr = getdata("inode");
51 meminfostr = getdata("meminfo");
52 msgsstr = getdata("msgs");
53 netstatstr = getdata("netstat");
54 ifstatstr = getdata("ifstat");
55 portsstr = getdata("ports");
56 vmstatstr = getdata("vmstat");
57
58 unix_cpu_report(hostname, clienttype, os, hinfo, fromline, timestr, uptimestr, clockstr, msgcachestr,
59 whostr, 0, psstr, 0, topstr);
60 unix_disk_report(hostname, clienttype, os, hinfo, fromline, timestr, "Avail", "Capacity", "Mounted", dfstr);
61 unix_inode_report(hostname, clienttype, os, hinfo, fromline, timestr, "ifree", "%iused", "Mounted", inodestr);
62 unix_procs_report(hostname, clienttype, os, hinfo, fromline, timestr, "COMMAND", NULL, psstr);
63 unix_ports_report(hostname, clienttype, os, hinfo, fromline, timestr, 3, 4, 5, portsstr);
64
65 msgs_report(hostname, clienttype, os, hinfo, fromline, timestr, msgsstr);
66 file_report(hostname, clienttype, os, hinfo, fromline, timestr);
67 linecount_report(hostname, clienttype, os, hinfo, fromline, timestr);
68 deltacount_report(hostname, clienttype, os, hinfo, fromline, timestr);
69
70 unix_netstat_report(hostname, clienttype, os, hinfo, fromline, timestr, netstatstr);
71 unix_ifstat_report(hostname, clienttype, os, hinfo, fromline, timestr, ifstatstr);
72 unix_vmstat_report(hostname, clienttype, os, hinfo, fromline, timestr, vmstatstr);
73
74 if (meminfostr) {
75 unsigned long memphystotal, memphysfree, memphysused;
76 unsigned long memswaptotal, memswapfree, memswapused;
77 int found = 0;
78
79 memphystotal = memphysfree = memphysused = 0;
80 memswaptotal = memswapfree = memswapused = 0;
81
82 p = strstr(meminfostr, "Total:"); if (p) { memphystotal = atol(p+6); found++; }
83 p = strstr(meminfostr, "Free:"); if (p) { memphysfree = atol(p+5); found++; }
84 memphysused = memphystotal - memphysfree;
85 p = strstr(meminfostr, "Swaptotal:"); if (p) { memswaptotal = atol(p+10); found++; }
86 p = strstr(meminfostr, "Swapused:"); if (p) { memswapused = atol(p+9); found++; }
87 memswapfree = memswaptotal - memswapused;
88
89 if (found == 4) {
90 unix_memory_report(hostname, clienttype, os, hinfo, fromline, timestr,
91 memphystotal, memphysused,
92 -1, -1,
93 memswaptotal, memswapused);
94 }
95 }
96
97 splitmsg_done();
98 }
99
100