diff options
author | Holger Weiss <holger@zedat.fu-berlin.de> | 2013-09-30 00:03:24 +0200 |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2013-09-30 00:03:24 +0200 |
commit | 0b6423f9c99d9edf8c96fefd0f6c453859395aa1 (patch) | |
tree | 1c2b6b21704a294940f87c7892676998d8371707 /web/attachments/268575-patch.check_mysql.c | |
download | site-0b6423f9c99d9edf8c96fefd0f6c453859395aa1.tar.gz |
Import Nagios Plugins site
Import the Nagios Plugins web site, Cronjobs, infrastructure scripts,
and configuration files.
Diffstat (limited to 'web/attachments/268575-patch.check_mysql.c')
-rw-r--r-- | web/attachments/268575-patch.check_mysql.c | 289 |
1 files changed, 289 insertions, 0 deletions
diff --git a/web/attachments/268575-patch.check_mysql.c b/web/attachments/268575-patch.check_mysql.c new file mode 100644 index 0000000..cbcc110 --- /dev/null +++ b/web/attachments/268575-patch.check_mysql.c | |||
@@ -0,0 +1,289 @@ | |||
1 | 68,87d67 | ||
2 | < int strIndexOf(char *string1, char *string2); | ||
3 | < char *strSubstring(char *string1, char *string2, int StartingPos, int EndPos); | ||
4 | < char *GetThreadsPerfdata(char *stringtoparse); | ||
5 | < char *GetQuestionsPerfdata(char *stringtoparse); | ||
6 | < char *GetSQPerfdata(char *stringtoparse); | ||
7 | < char *GetOpensPerfdata(char *stringtoparse); | ||
8 | < char *GetFTPerfdata(char *stringtoparse); | ||
9 | < char *GetOTPerfdata(char *stringtoparse); | ||
10 | < char *GetQPSAPerfdata(char *stringtoparse); | ||
11 | < | ||
12 | < struct mysql_statistics | ||
13 | < { | ||
14 | < char *ThreadsPerfdata; | ||
15 | < char *QuestionsPerfdata; | ||
16 | < char *SQPerfdata; | ||
17 | < char *OpensPerfdata; | ||
18 | < char *FTPerfdata; | ||
19 | < char *OTPerfdata; | ||
20 | < char *QPSAPerfdata; | ||
21 | < }; | ||
22 | 102,105d81 | ||
23 | < | ||
24 | < /* variables needed to parse */ | ||
25 | < char *StringToParse; | ||
26 | < struct mysql_statistics Stats; | ||
27 | 138,154d113 | ||
28 | < /* parse the server stats */ | ||
29 | < strcpy(StringToParse, result); | ||
30 | < | ||
31 | < Stats.ThreadsPerfdata = GetThreadsPerfdata(StringToParse); | ||
32 | < strcpy(StringToParse, result); | ||
33 | < Stats.QuestionsPerfdata = GetQuestionsPerfdata(StringToParse); | ||
34 | < strcpy(StringToParse, result); | ||
35 | < Stats.SQPerfdata = GetSQPerfdata(StringToParse); | ||
36 | < strcpy(StringToParse, result); | ||
37 | < Stats.OpensPerfdata = GetOpensPerfdata(StringToParse); | ||
38 | < strcpy(StringToParse, result); | ||
39 | < Stats.FTPerfdata = GetFTPerfdata(StringToParse); | ||
40 | < strcpy(StringToParse, result); | ||
41 | < Stats.OTPerfdata = GetOTPerfdata(StringToParse); | ||
42 | < strcpy(StringToParse, result); | ||
43 | < Stats.QPSAPerfdata = GetQPSAPerfdata(StringToParse); | ||
44 | < | ||
45 | 270c229 | ||
46 | < printf ("%s %s | %s %s %s %s %s %s %s\n", result, slaveresult, Stats.ThreadsPerfdata, Stats.SQPerfdata, Stats.OpensPerfdata, Stats.FTPerfdata, Stats.OTPerfdata, Stats.QPSAPerfdata); | ||
47 | --- | ||
48 | > printf ("%s %s\n", result, slaveresult); | ||
49 | 272c231 | ||
50 | < printf ("%s | %s %s %s %s %s %s %s\n", result, Stats.ThreadsPerfdata, Stats.QuestionsPerfdata, Stats.SQPerfdata, Stats.OpensPerfdata, Stats.FTPerfdata, Stats.OTPerfdata, Stats.QPSAPerfdata); | ||
51 | --- | ||
52 | > printf ("%s\n", result); | ||
53 | 278,512d236 | ||
54 | < char | ||
55 | < *GetQPSAPerfdata(char *stringtoparse) | ||
56 | < { | ||
57 | < int Start = 0; | ||
58 | < int End = 0; | ||
59 | < char *qpsa; | ||
60 | < char *output; | ||
61 | < Start = strIndexOf("Queries per second avg\0", stringtoparse); | ||
62 | < End = strlen(stringtoparse); | ||
63 | < | ||
64 | < qpsa = strSubstring(qpsa, stringtoparse, Start, End); | ||
65 | < qpsa = strSubstring(qpsa, qpsa, strIndexOf(" \0", qpsa) + 1, strlen(qpsa)); | ||
66 | < qpsa = strSubstring(qpsa, qpsa, strIndexOf(" \0", qpsa) + 1, strlen(qpsa)); | ||
67 | < qpsa = strSubstring(qpsa, qpsa, strIndexOf(" \0", qpsa) + 1, strlen(qpsa)); | ||
68 | < qpsa = strSubstring(qpsa, qpsa, strIndexOf(" \0", qpsa) + 1, strlen(qpsa)); | ||
69 | < printf("%s", qpsa); | ||
70 | < asprintf(&output, "%s", fperfdata("queries_per_second_avg", atof(qpsa), "", | ||
71 | < FALSE, 0, | ||
72 | < FALSE, 0, | ||
73 | < TRUE, 0, | ||
74 | < FALSE, 0)); | ||
75 | < | ||
76 | < return output; | ||
77 | < } | ||
78 | < | ||
79 | < char | ||
80 | < *GetOTPerfdata(char *stringtoparse) | ||
81 | < { | ||
82 | < int Start = 0; | ||
83 | < int End = 0; | ||
84 | < char *ot; | ||
85 | < char *output; | ||
86 | < Start = strIndexOf("Open tables\0", stringtoparse); | ||
87 | < End = strIndexOf("Queries per second avg\0", stringtoparse); | ||
88 | < | ||
89 | < ot = strSubstring(ot, stringtoparse, Start, End - 2); | ||
90 | < ot = strSubstring(ot, ot, strIndexOf(" \0", ot) + 1, strlen(ot)); | ||
91 | < ot = strSubstring(ot, ot, strIndexOf(" \0", ot) + 1, strlen(ot)); | ||
92 | < asprintf(&output, "%s", perfdata("open_tables", atoi(ot), "", | ||
93 | < FALSE, 0, | ||
94 | < FALSE, 0, | ||
95 | < TRUE, 0, | ||
96 | < FALSE, 0)); | ||
97 | < | ||
98 | < return output; | ||
99 | < } | ||
100 | < | ||
101 | < char | ||
102 | < *GetFTPerfdata(char *stringtoparse) | ||
103 | < { | ||
104 | < int Start = 0; | ||
105 | < int End = 0; | ||
106 | < char *ft; | ||
107 | < char *output; | ||
108 | < Start = strIndexOf("Flush tables\0", stringtoparse); | ||
109 | < End = strIndexOf("Open tables\0", stringtoparse); | ||
110 | < | ||
111 | < ft = strSubstring(ft, stringtoparse, Start, End - 2); | ||
112 | < ft = strSubstring(ft, ft, strIndexOf(" \0", ft) + 1, strlen(ft)); | ||
113 | < ft = strSubstring(ft, ft, strIndexOf(" \0", ft) + 1, strlen(ft)); | ||
114 | < asprintf(&output, "%s", perfdata("flush_tables", atoi(ft), "", | ||
115 | < FALSE, 0, | ||
116 | < FALSE, 0, | ||
117 | < TRUE, 0, | ||
118 | < FALSE, 0)); | ||
119 | < | ||
120 | < return output; | ||
121 | < } | ||
122 | < | ||
123 | < char | ||
124 | < *GetOpensPerfdata(char *stringtoparse) | ||
125 | < { | ||
126 | < int Start = 0; | ||
127 | < int End = 0; | ||
128 | < char *opens; | ||
129 | < char *output; | ||
130 | < Start = strIndexOf("Opens\0", stringtoparse); | ||
131 | < End = strIndexOf("Flush tables\0", stringtoparse); | ||
132 | < | ||
133 | < opens = strSubstring(opens, stringtoparse, Start, End - 2); | ||
134 | < opens = strSubstring(opens, opens, strIndexOf(" \0", opens) + 1, strlen(opens)); | ||
135 | < asprintf(&output, "%s", perfdata("opens", atoi(opens), "", | ||
136 | < FALSE, 0, | ||
137 | < FALSE, 0, | ||
138 | < TRUE, 0, | ||
139 | < FALSE, 0)); | ||
140 | < | ||
141 | < return output; | ||
142 | < } | ||
143 | < | ||
144 | < char | ||
145 | < *GetSQPerfdata(char *stringtoparse) | ||
146 | < { | ||
147 | < int Start = 0; | ||
148 | < int End = 0; | ||
149 | < char *slowqueries; | ||
150 | < char *output; | ||
151 | < Start = strIndexOf("Slow queries\0", stringtoparse); | ||
152 | < End = strIndexOf("Opens\0", stringtoparse); | ||
153 | < | ||
154 | < slowqueries = strSubstring(slowqueries, stringtoparse, Start, End - 2); | ||
155 | < slowqueries = strSubstring(slowqueries, slowqueries, strIndexOf(" \0", slowqueries) + 1, strlen(slowqueries)); | ||
156 | < slowqueries = strSubstring(slowqueries, slowqueries, strIndexOf(" \0", slowqueries) + 1, strlen(slowqueries)); | ||
157 | < asprintf(&output, "%s", perfdata("slow_queries", atoi(slowqueries), "", | ||
158 | < FALSE, 0, | ||
159 | < FALSE, 0, | ||
160 | < TRUE, 0, | ||
161 | < FALSE, 0)); | ||
162 | < | ||
163 | < return output; | ||
164 | < } | ||
165 | < | ||
166 | < char | ||
167 | < *GetQuestionsPerfdata(char *stringtoparse) | ||
168 | < { | ||
169 | < int Start = 0; | ||
170 | < int End = 0; | ||
171 | < char *questions; | ||
172 | < char *output; | ||
173 | < Start = strIndexOf("Questions\0", stringtoparse); | ||
174 | < End = strIndexOf("Slow queries\0", stringtoparse); | ||
175 | < | ||
176 | < questions = strSubstring(questions, stringtoparse, Start, End - 2); | ||
177 | < questions = strSubstring(questions, questions, strIndexOf(" \0", questions) + 1, strlen(questions)); | ||
178 | < asprintf(&output, "%s", perfdata("questions", atoi(questions), "", | ||
179 | < FALSE, 0, | ||
180 | < FALSE, 0, | ||
181 | < TRUE, 0, | ||
182 | < FALSE, 0)); | ||
183 | < | ||
184 | < return output; | ||
185 | < } | ||
186 | < | ||
187 | < char | ||
188 | < *GetThreadsPerfdata(char *stringtoparse) | ||
189 | < { | ||
190 | < int Start = 0; | ||
191 | < int End = 0; | ||
192 | < char *threads; | ||
193 | < char *output; | ||
194 | < | ||
195 | < Start = strIndexOf("Threads\0", stringtoparse); | ||
196 | < End = strIndexOf("Questions\0", stringtoparse); | ||
197 | < | ||
198 | < threads = strSubstring(threads, stringtoparse, Start, End - 2); | ||
199 | < threads = strSubstring(threads, threads, strIndexOf(" \0", threads) + 1, strlen(threads)); | ||
200 | < asprintf(&output, "%s", perfdata("threads", atoi(threads), "", | ||
201 | < FALSE, 0, | ||
202 | < FALSE, 0, | ||
203 | < TRUE, 0, | ||
204 | < FALSE, 0)); | ||
205 | < | ||
206 | < return output; | ||
207 | < } | ||
208 | < | ||
209 | < /* takes the substring from string1 between startingpos and the startingpos plus the length, | ||
210 | < all is returned */ | ||
211 | < char | ||
212 | < *strSubstring(char *string1, char *string2, int StartingPos, int EndPos) | ||
213 | < { | ||
214 | < /* current position in string2 */ | ||
215 | < int CurPos = 0; | ||
216 | < /* current position in string1 */ | ||
217 | < int String1Pos = 0; | ||
218 | < char *NULLChar = "\0"; | ||
219 | < | ||
220 | < for (CurPos = StartingPos; CurPos < EndPos; CurPos++) | ||
221 | < { | ||
222 | < string1[String1Pos] = string2[CurPos]; | ||
223 | < String1Pos++; | ||
224 | < } | ||
225 | < | ||
226 | < string1[String1Pos] = *NULLChar; | ||
227 | < | ||
228 | < return string1; | ||
229 | < } | ||
230 | < | ||
231 | < /* gets the starting position of string1 in string2, | ||
232 | < if string1 is not contained in string2 then the function returns -1 */ | ||
233 | < int | ||
234 | < strIndexOf (char *string1, char *string2) | ||
235 | < { | ||
236 | < /* current position in string2 */ | ||
237 | < int CurPos = 0; | ||
238 | < /* the amount of matches found after the startingposition was found */ | ||
239 | < int CharsFound = 0; | ||
240 | < /* the starting position of string1 in string2 */ | ||
241 | < int StartingPos = -1; | ||
242 | < /* length of string1 */ | ||
243 | < int Length1 = strlen(string1); | ||
244 | < /* Length of string2 */ | ||
245 | < int Length2 = strlen(string2); | ||
246 | < /* the maximum length of the search */ | ||
247 | < int MaxLength = 0; | ||
248 | < | ||
249 | < /* check if string2 is longer the string1, if not tell the program that something went wrong */ | ||
250 | < if (Length2 < Length1) | ||
251 | < { | ||
252 | < return -2; | ||
253 | < } | ||
254 | < | ||
255 | < /* calculate the max length of the search */ | ||
256 | < MaxLength = Length2; | ||
257 | < | ||
258 | < for (CurPos = 0; CurPos != MaxLength; CurPos++) | ||
259 | < { | ||
260 | < if (CharsFound == Length1) | ||
261 | < { | ||
262 | < return StartingPos; | ||
263 | < } | ||
264 | < | ||
265 | < if (StartingPos == -1) | ||
266 | < { | ||
267 | < if (string2[CurPos] == string1[CharsFound]) | ||
268 | < { | ||
269 | < StartingPos = CurPos; | ||
270 | < CharsFound++; | ||
271 | < } | ||
272 | < } | ||
273 | < else | ||
274 | < { | ||
275 | < if (string2[CurPos] == string1[CharsFound]) | ||
276 | < { | ||
277 | < CharsFound++; | ||
278 | < } | ||
279 | < else | ||
280 | < { | ||
281 | < CharsFound = 0; | ||
282 | < StartingPos = -1; | ||
283 | < } | ||
284 | < } | ||
285 | < } | ||
286 | < | ||
287 | < return -1; | ||
288 | < } | ||
289 | |||