PageRenderTime 61ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/src/com/clavain/utils/Database.java

https://gitlab.com/goolic/MuninMX
Java | 591 lines | 523 code | 33 blank | 35 comment | 24 complexity | 7178b1f7011c0c53cbaf1139e6e333eb MD5 | raw file
  1. /*
  2. * MuninMX
  3. * Written by Enrico Kern, kern@clavain.com
  4. * www.clavain.com
  5. *
  6. * Licensed to the Apache Software Foundation (ASF) under one
  7. * or more contributor license agreements. See the NOTICE file
  8. * distributed with this work for additional information
  9. * regarding copyright ownership. The ASF licenses this file
  10. * to you under the Apache License, Version 2.0 (the
  11. * "License"); you may not use this file except in compliance
  12. * with the License. You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing,
  17. * software distributed under the License is distributed on an
  18. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19. * KIND, either express or implied. See the License for the
  20. * specific language governing permissions and limitations
  21. * under the License.
  22. */
  23. package com.clavain.utils;
  24. import com.clavain.alerts.Alert;
  25. import com.clavain.json.ServiceCheck;
  26. import com.clavain.json.User;
  27. import com.clavain.munin.MuninGraph;
  28. import com.clavain.munin.MuninNode;
  29. import com.clavain.munin.MuninPlugin;
  30. import static com.clavain.muninmxcd.logger;
  31. import static com.clavain.muninmxcd.m;
  32. import java.sql.Connection;
  33. import java.sql.DriverManager;
  34. import java.sql.ResultSet;
  35. import java.sql.SQLException;
  36. import java.util.ArrayList;
  37. import java.util.Properties;
  38. import java.util.concurrent.CopyOnWriteArrayList;
  39. import static com.clavain.muninmxcd.p;
  40. import static com.clavain.muninmxcd.v_serviceChecks;
  41. import com.clavain.rca.Analyzer;
  42. import static com.clavain.utils.Generic.getMuninNode;
  43. import static com.clavain.utils.Quartz.scheduleCustomIntervalJob;
  44. import com.google.gson.Gson;
  45. import com.google.gson.GsonBuilder;
  46. import com.mongodb.BasicDBObject;
  47. import com.mongodb.DB;
  48. import com.mongodb.DBCollection;
  49. import com.mongodb.WriteConcern;
  50. import java.lang.reflect.Modifier;
  51. import java.util.Iterator;
  52. import java.util.logging.Level;
  53. import java.util.logging.Logger;
  54. import static com.clavain.utils.Generic.getStampFromTimeAndZone;
  55. /**
  56. *
  57. * @author enricokern
  58. */
  59. public class Database {
  60. public static String clearStringForSQL(String p_str)
  61. {
  62. if(p_str == null)
  63. {
  64. return p_str;
  65. }
  66. String retval = p_str;
  67. retval = retval.replaceAll("'","");
  68. retval = retval.replaceAll("<","");
  69. retval = retval.replaceAll("`", "");
  70. retval = retval.replaceAll("ยด", "");
  71. retval = retval.replaceAll(";", "");
  72. return retval;
  73. }
  74. // Establish a connection to the database
  75. public static Connection connectToDatabase(Properties p)
  76. {
  77. Connection conn;
  78. try {
  79. logger.debug("Connecting to MySQL");
  80. conn =
  81. DriverManager.getConnection("jdbc:mysql://"+p.getProperty("mysql.host")+":"+p.getProperty("mysql.port")+"/"+p.getProperty("mysql.db")+"?" +
  82. "user="+p.getProperty("mysql.user")+"&password="+p.getProperty("mysql.pass")+"&autoReconnect=true&failOverReadOnly=false&maxReconnects=10");
  83. return(conn);
  84. } catch (Exception ex) {
  85. // handle any errors
  86. logger.fatal("Error connecting to database: " + ex.getMessage());
  87. return(null);
  88. }
  89. }
  90. public static void dbSetRcaFinished(String p_rcaId)
  91. {
  92. try {
  93. Connection conn = connectToDatabase(p);
  94. java.sql.Statement stmt = conn.createStatement();
  95. stmt.executeUpdate("UPDATE rca SET is_finished = 1 WHERE rcaId = '" + p_rcaId+"'");
  96. conn.close();
  97. } catch (Exception ex)
  98. {
  99. logger.error("[RCA] Error in dbSetRcaFinished: " + ex.getLocalizedMessage());
  100. ex.printStackTrace();
  101. }
  102. }
  103. public static void dbSetRcaOutput(Analyzer p_analyzer)
  104. {
  105. try {
  106. Gson gson = new GsonBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT).create();
  107. String json = gson.toJson(p_analyzer);
  108. Connection conn = connectToDatabase(p);
  109. java.sql.Statement stmt = conn.createStatement();
  110. stmt.executeUpdate("UPDATE rca SET `output` = '"+json+"' WHERE rcaId = '" + p_analyzer.getRcaId()+"'");
  111. conn.close();
  112. } catch (Exception ex)
  113. {
  114. logger.error("[RCA] Error in dbSetRcaOutput: " + ex.getLocalizedMessage());
  115. ex.printStackTrace();
  116. }
  117. }
  118. public static void dbUpdatePluginForNode(Integer nodeId, MuninPlugin mp)
  119. {
  120. try {
  121. Connection conn = connectToDatabase(p);
  122. java.sql.Statement stmt = conn.createStatement();
  123. ResultSet rs = stmt.executeQuery("SELECT * from node_plugins WHERE node_id = "+nodeId+" AND pluginname = '"+clearStringForSQL(mp.getPluginName())+"'");
  124. if(rowCount(rs) < 1)
  125. {
  126. logger.info("[Node " + nodeId + "] Adding Plugin: " + mp.getPluginName() + " to database");
  127. stmt.executeUpdate("INSERT INTO node_plugins (node_id,pluginname,plugintitle,plugininfo,plugincategory) VALUES ("+nodeId+",'"+clearStringForSQL(mp.getPluginName())+"','"+clearStringForSQL(mp.getPluginTitle())+"','"+clearStringForSQL(mp.getPluginInfo())+"','"+clearStringForSQL(mp.getStr_PluginCategory())+"')");
  128. }
  129. else
  130. {
  131. rs = stmt.executeQuery("SELECT * from node_plugins WHERE node_id = "+nodeId+" AND pluginname = '"+clearStringForSQL(mp.getPluginName())+"'");
  132. while(rs.next())
  133. {
  134. // plugin title or/and category change?
  135. if(!clearStringForSQL(mp.getPluginTitle()).equals(rs.getString("plugintitle")))
  136. {
  137. logger.info("[Node " + nodeId + "] Plugin: " + mp.getPluginName() + " got new Title. Updating Title");
  138. stmt.executeUpdate("UPDATE node_plugins SET plugintitle = '" + clearStringForSQL(mp.getPluginTitle()) + "' WHERE node_id = "+nodeId+" AND pluginname = '"+clearStringForSQL(mp.getPluginName())+"'");
  139. }
  140. if(!clearStringForSQL(mp.getStr_PluginCategory()).equals(rs.getString("plugincategory")))
  141. {
  142. logger.info("[Node " + nodeId + "] Plugin: " + mp.getPluginName() + " got new category. Updating Category (New: "+mp.getStr_PluginCategory()+" Old: "+rs.getString("plugincategory")+" )");
  143. stmt.executeUpdate("UPDATE node_plugins SET plugincategory = '" + clearStringForSQL(mp.getStr_PluginCategory()) + "' WHERE node_id = "+nodeId+" AND pluginname = '"+clearStringForSQL(mp.getPluginName())+"'");
  144. }
  145. if(!clearStringForSQL(mp.getStr_LineMode()).equals(rs.getString("linemode")))
  146. {
  147. logger.info("[Node " + nodeId + "] Plugin: " + mp.getPluginName() + " got new linemode. Updating linemode (New: "+mp.getStr_LineMode()+" Old: "+rs.getString("linemode")+" )");
  148. stmt.executeUpdate("UPDATE node_plugins SET linemode = '" + clearStringForSQL(mp.getStr_LineMode()) + "' WHERE node_id = "+nodeId+" AND pluginname = '"+clearStringForSQL(mp.getPluginName())+"'");
  149. }
  150. }
  151. }
  152. conn.close();
  153. } catch (Exception ex)
  154. {
  155. logger.error("Error in dbUpdatePlugin: " + ex.getLocalizedMessage());
  156. ex.printStackTrace();
  157. }
  158. }
  159. public static void dbUpdateLastContact(Integer nodeId)
  160. {
  161. try {
  162. Connection conn = connectToDatabase(p);
  163. java.sql.Statement stmt = conn.createStatement();
  164. stmt.executeUpdate("UPDATE nodes SET last_contact = NOW() WHERE id = " + nodeId);
  165. conn.close();
  166. } catch (Exception ex)
  167. {
  168. logger.error("Error in dbUpdateLastContact: " + ex.getLocalizedMessage());
  169. ex.printStackTrace();
  170. }
  171. }
  172. public static void dbUpdateAllPluginsForNode(MuninNode p_mn)
  173. {
  174. if(p_mn.getPluginList().size() > 0)
  175. {
  176. logger.info("[Job: " + p_mn.getHostname() + "] Updating Database");
  177. // update graphs in database too
  178. for(MuninPlugin it_pl : p_mn.getPluginList()) {
  179. if(it_pl.getGraphs().size() > 0)
  180. {
  181. dbUpdatePluginForNode(p_mn.getNode_id(),it_pl);
  182. }
  183. }
  184. // delete now missing plugins
  185. dbDeleteMissingPlugins(p_mn.getNode_id(),p_mn.getPluginList());
  186. logger.info("[Job: " + p_mn.getHostname() + "] Databaseupdate Done");
  187. }
  188. else
  189. {
  190. logger.warn("[Job: " + p_mn.getHostname() + "] Databaseupdate skipped. Pluginsize is 0");
  191. }
  192. }
  193. public static User getUserFromDatabase(Integer user_id)
  194. {
  195. User luser = null;
  196. try
  197. {
  198. Connection conn = connectToDatabase(p);
  199. java.sql.Statement stmt = conn.createStatement();
  200. ResultSet rs = stmt.executeQuery("SELECT * FROM users WHERE id = " + user_id);
  201. while(rs.next())
  202. {
  203. luser = new User();
  204. luser.setAccessgroup(rs.getString("accessgroup"));
  205. luser.setUsername(rs.getString("username"));
  206. luser.setUserrole(rs.getString("userrole"));
  207. luser.setUser_id(rs.getInt("id"));
  208. }
  209. } catch (Exception ex)
  210. {
  211. return null;
  212. }
  213. return luser;
  214. }
  215. public static ServiceCheck getServiceCheckFromDatabase(Integer cid)
  216. {
  217. ServiceCheck sc = null;
  218. try
  219. {
  220. Connection conn = connectToDatabase(p);
  221. java.sql.Statement stmt = conn.createStatement();
  222. ResultSet rs = stmt.executeQuery("SELECT * FROM service_checks WHERE id = " + cid);
  223. while(rs.next())
  224. {
  225. Gson gson = new Gson();
  226. sc = gson.fromJson(rs.getString("json"), ServiceCheck.class);
  227. sc.setCid(rs.getInt("id"));
  228. sc.setUser_id(rs.getInt("user_id"));
  229. v_serviceChecks.add(sc);
  230. logger.info("* " + sc.getCheckname() + " Service Check added from database");
  231. }
  232. conn.close();
  233. } catch (Exception ex)
  234. {
  235. logger.error("getServiceCheckFromDatabase Error: " + ex.getLocalizedMessage());
  236. ex.printStackTrace();
  237. return null;
  238. }
  239. return sc;
  240. }
  241. public static MuninNode getMuninNodeFromDatabase(Integer nodeId)
  242. {
  243. MuninNode l_mn = new MuninNode();
  244. try
  245. {
  246. Connection conn = connectToDatabase(p);
  247. java.sql.Statement stmt = conn.createStatement();
  248. ResultSet rs = stmt.executeQuery("SELECT * FROM nodes WHERE id = " + nodeId);
  249. while(rs.next())
  250. {
  251. l_mn.setHostname(rs.getString("hostname"));
  252. l_mn.setNodename(rs.getString("hostname"));
  253. l_mn.setNode_id(rs.getInt("id"));
  254. l_mn.setPort(rs.getInt("port"));
  255. l_mn.setUser_id(rs.getInt("user_id"));
  256. l_mn.setQueryInterval(rs.getInt("query_interval"));
  257. l_mn.setStr_via(rs.getString("via_host"));
  258. l_mn.setAuthpw(rs.getString("authpw"));
  259. l_mn.setGroup(rs.getString("groupname"));
  260. }
  261. conn.close();
  262. } catch (Exception ex)
  263. {
  264. logger.error("getMuninNodeFromDatabase Error: " + ex.getLocalizedMessage());
  265. ex.printStackTrace();
  266. return null;
  267. }
  268. if(l_mn.getHostname().trim().equals("unset"))
  269. {
  270. return null;
  271. }
  272. else
  273. {
  274. return l_mn;
  275. }
  276. }
  277. public static void dbDeleteMissingPlugins(Integer nodeId,CopyOnWriteArrayList<MuninPlugin> mps)
  278. {
  279. try {
  280. Connection conn = connectToDatabase(p);
  281. java.sql.Statement stmt = conn.createStatement();
  282. ResultSet rs = stmt.executeQuery("SELECT * from node_plugins WHERE node_id = "+nodeId);
  283. boolean found = false;
  284. while(rs.next())
  285. {
  286. found = false;
  287. for(MuninPlugin mp : mps)
  288. {
  289. if(mp.getPluginName().equals(rs.getString("pluginname")))
  290. {
  291. found = true;
  292. }
  293. }
  294. if(found == false)
  295. {
  296. logger.info("[Node " + nodeId + "] Removing Plugin: " + rs.getString("pluginname") + " from Database. Not found on munin node anymore");
  297. java.sql.Statement stmtt = conn.createStatement();
  298. stmtt.executeUpdate("DELETE FROM node_plugins WHERE id = "+rs.getInt("id"));
  299. }
  300. }
  301. conn.close();
  302. } catch (Exception ex)
  303. {
  304. logger.error("Error in dbDeleteMissingPlugins: " + ex.getLocalizedMessage());
  305. }
  306. }
  307. public static void dbScheduleAllCustomJobs()
  308. {
  309. try
  310. {
  311. Connection conn = connectToDatabase(p);
  312. java.sql.Statement stmt = conn.createStatement();
  313. ResultSet rs = stmt.executeQuery("SELECT * FROM plugins_custom_interval");
  314. while(rs.next())
  315. {
  316. scheduleCustomIntervalJob(rs.getInt("id"));
  317. }
  318. } catch (Exception ex)
  319. {
  320. logger.error("Startup Schedule for Custom Jobs failed." + ex.getLocalizedMessage());
  321. ex.printStackTrace();
  322. }
  323. }
  324. public static void dbAddAllAlerts()
  325. {
  326. try
  327. {
  328. Connection conn = connectToDatabase(p);
  329. conn.setReadOnly(true);
  330. //
  331. java.sql.Statement stmt = conn.createStatement();
  332. ResultSet rs = stmt.executeQuery("SELECT alerts.*,nodes.hostname FROM alerts LEFT JOIN nodes ON alerts.node_id = nodes.id");
  333. while(rs.next())
  334. {
  335. Alert av = new Alert();
  336. av.setAlert_id(rs.getInt("id"));
  337. av.setCondition(rs.getString("condition"));
  338. av.setGraphName(rs.getString("graphname"));
  339. av.setPluginName(rs.getString("pluginname"));
  340. av.setRaise_value(rs.getBigDecimal("raise_value"));
  341. av.setNum_samples(rs.getInt("num_samples"));
  342. av.setAlert_limit(rs.getInt("alert_limit"));
  343. av.setHostname(rs.getString("hostname"));
  344. av.setNode_id(rs.getInt("node_id"));
  345. com.clavain.muninmxcd.v_alerts.add(av);
  346. }
  347. logger.info("Startup for Alerts Done");
  348. } catch (Exception ex)
  349. {
  350. logger.error("Startup for Alerts failed. retrying in 60 seconds" + ex.getLocalizedMessage());
  351. try {
  352. Thread.sleep(60000);
  353. dbAddAllAlerts();
  354. } catch (InterruptedException ex1) {
  355. logger.error("Startup for Alerts restart failed");
  356. }
  357. ex.printStackTrace();
  358. }
  359. }
  360. public static boolean dbAddAllAlertWithId(Integer p_aid)
  361. {
  362. boolean retval = false;
  363. try
  364. {
  365. Connection conn = connectToDatabase(p);
  366. java.sql.Statement stmt = conn.createStatement();
  367. ResultSet rs = stmt.executeQuery("SELECT alerts.*,nodes.hostname FROM alerts LEFT JOIN nodes ON alerts.node_id = nodes.id WHERE alerts.id = " + p_aid);
  368. while(rs.next())
  369. {
  370. Alert av = new Alert();
  371. av.setAlert_id(rs.getInt("id"));
  372. av.setCondition(rs.getString("condition"));
  373. av.setGraphName(rs.getString("graphname"));
  374. av.setPluginName(rs.getString("pluginname"));
  375. av.setRaise_value(rs.getBigDecimal("raise_value"));
  376. av.setNum_samples(rs.getInt("num_samples"));
  377. av.setAlert_limit(rs.getInt("alert_limit"));
  378. av.setHostname(rs.getString("hostname"));
  379. av.setNode_id(rs.getInt("node_id"));
  380. com.clavain.muninmxcd.v_alerts.add(av);
  381. retval = true;
  382. }
  383. } catch (Exception ex)
  384. {
  385. logger.error("Add Alert "+p_aid+" failed." + ex.getLocalizedMessage());
  386. ex.printStackTrace();
  387. }
  388. return retval;
  389. }
  390. public static MuninPlugin getMuninPluginForCustomJobFromDb(Integer p_id)
  391. {
  392. MuninPlugin retval = new MuninPlugin();
  393. try
  394. {
  395. Connection conn = connectToDatabase(p);
  396. java.sql.Statement stmt = conn.createStatement();
  397. ResultSet rs = stmt.executeQuery("SELECT plugins_custom_interval.*,plugins_custom_interval.query_interval AS second_interval , nodes.*, nodes.id AS nodeid, nodes.query_interval AS node_query_interval FROM `plugins_custom_interval` LEFT JOIN nodes ON plugins_custom_interval.node_id = nodes.id WHERE plugins_custom_interval.id = "+p_id);
  398. while(rs.next())
  399. {
  400. MuninNode l_node = getMuninNode(rs.getInt("nodeid"));
  401. if(l_node == null)
  402. {
  403. logger.error("getMuninPluginFromCustomInterval: cannot find MuninNode with id " + rs.getInt("nodeid") + " for custom interval: " + p_id);
  404. return null;
  405. }
  406. retval.set_IntervalIsSeconds(true);
  407. retval.set_NodeId(l_node.getNode_id());
  408. retval.setTo_time(rs.getInt("to_time"));
  409. retval.setFrom_time(rs.getInt("from_time"));
  410. retval.setTimezone(rs.getString("timezone"));
  411. String str_PluginName = rs.getString("pluginname").trim();
  412. retval.setUser_id(l_node.getUser_id());
  413. retval.setQuery_interval(rs.getInt("second_interval"));
  414. retval.setCrontab(rs.getString("crontab"));
  415. retval.setCustomId(p_id);
  416. // find plugin for custom interval and copy graphs and plugin informations
  417. Iterator it = l_node.getPluginList().iterator();
  418. while(it.hasNext())
  419. {
  420. MuninPlugin l_mp = (MuninPlugin) it.next();
  421. if(l_mp.getPluginName().equals(str_PluginName))
  422. {
  423. retval.setPluginInfo(l_mp.getPluginInfo());
  424. retval.setPluginLabel((l_mp.getPluginLabel()));
  425. retval.setPluginName(l_mp.getPluginName());
  426. retval.setPluginTitle(l_mp.getPluginTitle());
  427. retval.setStr_PluginCategory(l_mp.getStr_PluginCategory());
  428. // copy graph base informations
  429. Iterator git = l_mp.getGraphs().iterator();
  430. while(git.hasNext())
  431. {
  432. MuninGraph old_mg = (MuninGraph) git.next();
  433. MuninGraph new_mg = new MuninGraph();
  434. new_mg.setGraphDraw(old_mg.getGraphDraw());
  435. new_mg.setGraphInfo(old_mg.getGraphInfo());
  436. new_mg.setGraphLabel(old_mg.getGraphLabel());
  437. new_mg.setGraphName(old_mg.getGraphName());
  438. new_mg.setGraphType(old_mg.getGraphType());
  439. new_mg.setNegative(old_mg.isNegative());
  440. new_mg.setQueryInterval(rs.getInt("second_interval"));
  441. new_mg.setIntervalIsSeconds(true);
  442. retval.addGraph(new_mg);
  443. logger.info("getMuninPluginFromCustomInterval: added graph " + new_mg.getGraphName() + " for custom interval: " + p_id);
  444. }
  445. }
  446. }
  447. return retval;
  448. }
  449. } catch (Exception ex)
  450. {
  451. logger.error("Error in getMuninPluginFromCustomInterval: " + ex.getLocalizedMessage());
  452. ex.printStackTrace();
  453. retval = null;
  454. }
  455. return retval;
  456. }
  457. public static void dbUpdateNodeDistVerKernel(String p_sum,String p_dist, String p_ver, String p_kernel, int p_nodeid)
  458. {
  459. try
  460. {
  461. Connection conn = connectToDatabase(p);
  462. java.sql.Statement stmt = conn.createStatement();
  463. if(p_dist.contains("/etc/SuSE-release"))
  464. {
  465. p_dist = "SuSE";
  466. p_ver = "unknown";
  467. p_kernel = "unknown";
  468. }
  469. stmt.executeUpdate("UPDATE nodes SET trackpkg_sum = '"+clearStringForSQL(p_sum)+"', track_dist = '"+clearStringForSQL(p_dist)+"', track_ver = '"+clearStringForSQL(p_ver)+"', track_kernel = '"+clearStringForSQL(p_kernel)+"', track_update = NOW() WHERE id = " + p_nodeid);
  470. } catch (Exception ex)
  471. {
  472. logger.error("Error in dbUpdateNodeDistVerKernel (Node: "+p_nodeid+") - " + ex.getLocalizedMessage());
  473. }
  474. }
  475. public static boolean dbTrackLogChangedForNode(String p_sum, int p_nodeid)
  476. {
  477. boolean retval = false;
  478. try
  479. {
  480. Connection conn = connectToDatabase(p);
  481. java.sql.Statement stmt = conn.createStatement();
  482. ResultSet rs = stmt.executeQuery("SELECT id FROM nodes WHERE id = " + p_nodeid + " AND trackpkg_sum = '"+p_sum+"'");
  483. if(rowCount(rs) < 1)
  484. {
  485. retval = true;
  486. }
  487. } catch (Exception ex)
  488. {
  489. logger.error("Error in dbTrackLogChangedForNode (Node: "+p_nodeid+" Sum: "+p_sum+" ) - " + ex.getLocalizedMessage());
  490. }
  491. return retval;
  492. }
  493. public static void removeOldPackageTrack(int p_nodeid)
  494. {
  495. try {
  496. logger.info("Purging Package Logs for NodeID: " + p_nodeid);
  497. DB db;
  498. String dbName = com.clavain.muninmxcd.p.getProperty("mongo.dbessentials");
  499. db = m.getDB(dbName);
  500. db.setWriteConcern(WriteConcern.SAFE);
  501. DBCollection col = db.getCollection("trackpkg");
  502. BasicDBObject query = new BasicDBObject();
  503. query.append("node", p_nodeid);
  504. col.remove(query);
  505. db.setWriteConcern(WriteConcern.NONE);
  506. } catch (Exception ex)
  507. {
  508. logger.error("Error in removeOldPackageTrack: " + ex.getLocalizedMessage());
  509. }
  510. }
  511. public static int rowCount(ResultSet rs) throws SQLException
  512. {
  513. int rsCount = 0;
  514. while(rs.next())
  515. {
  516. //do your other per row stuff
  517. rsCount = rsCount + 1;
  518. }//end while
  519. return rsCount;
  520. }
  521. public static boolean serviceCheckGotDowntime(Integer cid, int timestamp)
  522. {
  523. boolean retval = false;
  524. try
  525. {
  526. Connection conn = connectToDatabase(p);
  527. java.sql.Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
  528. ResultSet rs = stmt.executeQuery("SELECT * FROM downtimes WHERE check_id = " + cid);
  529. if(rowCount(rs) > 0)
  530. {
  531. Integer ftime;
  532. Integer ttime;
  533. rs.beforeFirst();
  534. while(rs.next())
  535. {
  536. if(rs.getInt("repeating") == 1)
  537. {
  538. ftime = (int) getStampFromTimeAndZone(rs.getString("from_time"),rs.getString("timezone"));
  539. ttime = (int) getStampFromTimeAndZone(rs.getString("to_time"),rs.getString("timezone"));
  540. }
  541. else
  542. {
  543. ftime = Integer.parseInt(rs.getString("from_time"));
  544. ttime = Integer.parseInt(rs.getString("to_time"));
  545. }
  546. if(ftime < timestamp && timestamp < ttime)
  547. {
  548. return true;
  549. }
  550. }
  551. }
  552. } catch (Exception ex)
  553. {
  554. com.clavain.muninmxcd.logger.error("serviceCheckGotDowntime Error: " + ex.getLocalizedMessage());
  555. }
  556. return retval;
  557. }
  558. }