1 /*----------------------------------------------------------------------------*/
2 /* Xymon message daemon.                                                      */
3 /*                                                                            */
4 /* Client backend module for IRIX                                             */
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 irix_rcsid[] = "$Id: irix.c 7886 2016-02-02 20:16:19Z jccleaver $";
14 
handle_irix_client(char * hostname,char * clienttype,enum ostype_t os,void * hinfo,char * sender,time_t timestamp,char * clientdata)15 void handle_irix_client(char *hostname, char *clienttype, enum ostype_t os,
16 			void *hinfo, char *sender, time_t timestamp,
17 			char *clientdata)
18 {
19 	static pcre *memptn = NULL;
20 	char *timestr;
21 	char *uptimestr;
22 	char *clockstr;
23 	char *msgcachestr;
24 	char *whostr;
25 	char *psstr;
26 	char *topstr;
27 	char *dfstr;
28 	char *msgsstr;
29 	char *netstatstr;
30 	// char *sarstr;
31 	char *ifstatstr;
32 	char *portsstr;
33 
34 	char fromline[1024];
35 
36 	sprintf(fromline, "\nStatus message received from %s\n", sender);
37 
38 	splitmsg(clientdata);
39 
40 	timestr = getdata("date");
41 	uptimestr = getdata("uptime");
42 	clockstr = getdata("clock");
43 	msgcachestr = getdata("msgcache");
44 	whostr = getdata("who");
45 	psstr = getdata("ps");
46 	topstr = getdata("top");
47 	dfstr = getdata("df");
48 	msgsstr = getdata("msgs");
49 	netstatstr = getdata("netstat");
50 	ifstatstr = getdata("ifstat");
51 	// sarstr = getdata("sar");
52 	portsstr = getdata("ports");
53 
54 	unix_cpu_report(hostname, clienttype, os, hinfo, fromline, timestr, uptimestr, clockstr, msgcachestr,
55 			whostr, 0, psstr, 0, topstr);
56 	unix_disk_report(hostname, clienttype, os, hinfo, fromline, timestr, "Available", "Capacity", "Mounted", dfstr);
57 	unix_procs_report(hostname, clienttype, os, hinfo, fromline, timestr, "COMMAND", NULL, psstr);
58 	unix_ports_report(hostname, clienttype, os, hinfo, fromline, timestr, 3, 4, 5, portsstr);
59 
60 	msgs_report(hostname, clienttype, os, hinfo, fromline, timestr, msgsstr);
61 	file_report(hostname, clienttype, os, hinfo, fromline, timestr);
62 	linecount_report(hostname, clienttype, os, hinfo, fromline, timestr);
63 	deltacount_report(hostname, clienttype, os, hinfo, fromline, timestr);
64 
65 	unix_netstat_report(hostname, clienttype, os, hinfo, fromline, timestr, netstatstr);
66 	unix_ifstat_report(hostname, clienttype, os, hinfo, fromline, timestr, ifstatstr);
67 	/* unix_sar_report(hostname, clienttype, os, hinfo, fromline, timestr, sarstr); */
68 
69 	if (topstr) {
70 		char *memline, *eoln = NULL;
71 		int res;
72 		int ovector[20];
73 		char w[20];
74 		long memphystotal = -1, memphysused = -1, memphysfree = 0,
75 		     memacttotal = -1, memactused = -1, memactfree = -1,
76 		     memswaptotal = -1, memswapused = -1, memswapfree = 0;
77 
78 		if (!memptn) {
79 			memptn = compileregex("^Memory: (\\d+)M max, (\\d+)M avail, (\\d+)M free, (\\d+)M swap, (\\d+)M free swap");
80 		}
81 
82 		memline = strstr(topstr, "\nMemory:");
83 		if (memline) {
84 			memline++;
85 			eoln = strchr(memline, '\n'); if (eoln) *eoln = '\0';
86 
87 			res = pcre_exec(memptn, NULL, memline, strlen(memline), 0, 0, ovector, (sizeof(ovector)/sizeof(int)));
88 		}
89 		else res = -1;
90 
91 		if (res > 1) {
92 			pcre_copy_substring(memline, ovector, res, 1, w, sizeof(w));
93 			memphystotal = atol(w);
94 		}
95 		if (res > 2) {
96 			pcre_copy_substring(memline, ovector, res, 2, w, sizeof(w));
97 			memactfree = atol(w);
98 			memacttotal = memphystotal;
99 			memactused = memphystotal - memactfree;
100 		}
101 		if (res > 3) {
102 			pcre_copy_substring(memline, ovector, res, 3, w, sizeof(w));
103 			memphysfree = atol(w);
104 			memphysused = memphystotal - memphysfree;
105 		}
106 
107 		if (res > 4) {
108 			pcre_copy_substring(memline, ovector, res, 4, w, sizeof(w));
109 			memswaptotal = atol(w);
110 		}
111 		if (res > 5) {
112 			pcre_copy_substring(memline, ovector, res, 5, w, sizeof(w));
113 			memswapfree = atol(w);
114 		}
115 		memswapused = memswaptotal - memswapfree;
116 
117 		if (eoln) *eoln = '\n';
118 
119 		unix_memory_report(hostname, clienttype, os, hinfo, fromline, timestr,
120 				   memphystotal, memphysused, memacttotal, memactused, memswaptotal, memswapused);
121 	}
122 
123 	splitmsg_done();
124 }
125 
126