Guest User

Untitled

a guest
Dec 10th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. #include "cmon/alarms.h"
  2.  
  3. function readVariable(host1, myVar)
  4. {
  5.  
  6. _query = "SHOW GLOBAL VARIABLES LIKE '" + myVar + "'";
  7. retval = host1.executeSqlQuery(_query);
  8. //
  9. // If the SQL query failed we print the error message
  10. // and return false.
  11. //
  12. if (!retval["success"])
  13. {
  14. print("ERROR: ", retval["errorMessage"]);
  15. return false;
  16. }
  17. //
  18. // Processing the results.
  19. //
  20. result = retval["result"];
  21. nRows = result.rows();
  22. if (nRows==0)
  23. return false;
  24. var value;
  25. for (row = 0; row < nRows; ++row)
  26. {
  27. name = result[row, 0];
  28. value = result[row, 1];
  29. }
  30. return value;
  31. }
  32.  
  33. function getSingleValue(host1, _query)
  34. {
  35.  
  36. retval = host1.executeSqlQuery(_query);
  37. //
  38. // If the SQL query failed we print the error message
  39. // and return false.
  40. //
  41. var value=0;
  42.  
  43. if (!retval["success"])
  44. {
  45. print("ERROR: ", retval["errorMessage"]);
  46. return false;
  47. }
  48. //
  49. // Processing the results.
  50. //
  51. result = retval["result"];
  52. nRows = result.rows();
  53. if (nRows==0)
  54. return false;
  55. for (row = 0; row < nRows; ++row)
  56. {
  57. value = result[row, 0];
  58. }
  59. return value;
  60. }
  61.  
  62. function getResultSet(host1, _query)
  63. {
  64. retval = host1.executeSqlQuery(_query);
  65. return retval;
  66. }
  67.  
  68. function getValueMap(host1, _query)
  69. {
  70.  
  71. retval = host1.executeSqlQuery(_query);
  72. //
  73. // If the SQL query failed we print the error message
  74. // and return false.
  75. //
  76. var value={};
  77.  
  78. if (!retval["success"])
  79. {
  80. print("ERROR: ", retval["errorMessage"]);
  81. return false;
  82. }
  83. //
  84. // Processing the results.
  85. //
  86. result = retval["result"];
  87. nRows = result.rows();
  88. if (nRows==0)
  89. return false;
  90. var columns = result.size();
  91. for (row = 0; row < nRows; ++row)
  92. {
  93. value[row] = {};
  94. for(c = 0; c < columns; ++c)
  95. {
  96. value[row][c] = result[row, c];
  97. }
  98. }
  99. return value;
  100. }
  101.  
  102. function readStatusVariable(host, myVar)
  103. {
  104.  
  105. _query = "SHOW GLOBAL STATUS LIKE '" + myVar + "'";
  106. retval = host.executeSqlQuery(_query);
  107. //
  108. // If the SQL query failed we print the error message
  109. // and return false.
  110. //
  111. if (!retval["success"])
  112. {
  113. print("ERROR: ", retval["errorMessage"]);
  114. return false;
  115. }
  116.  
  117. //
  118. // Processing the results.
  119. //
  120. result = retval["result"];
  121. nRows = result.rows();
  122. for (row = 0; row < nRows; ++row)
  123. {
  124. name = result[row, 0];
  125. value = result[row, 1];
  126. }
  127. return value;
  128. }
  129.  
  130. function executeSqlCommand(host, _query)
  131. {
  132. retval = host.executeSqlCommand(_query);
  133. //
  134. // If the SQL query failed we print the error message
  135. // and return false.
  136. //
  137. if (!retval["success"])
  138. {
  139. print("ERROR: ", retval["errorMessage"]);
  140. return false;
  141. }
  142. return true;
  143. }
  144.  
  145.  
  146. function executeSqlCommand2(host, _query)
  147. {
  148. retval = host.executeSqlCommand(_query);
  149. return retval;
  150. }
  151.  
  152.  
  153. function checkPrecond(host)
  154. {
  155. var UPTIME=3600;
  156. var QPS = 10;
  157.  
  158. var uptime = readStatusVariable(host, "Uptime").toInt();
  159. var qps = readStatusVariable(host, "Queries").toInt() / uptime;
  160.  
  161. if (uptime > UPTIME && qps > QPS)
  162. return true;
  163. else
  164. return false;
  165. }
  166.  
  167. function setGlobalVariable(host, variable, value)
  168. {
  169. if (value.looksInteger() || value.looksULongLong())
  170. _query = "SET GLOBAL " + variable + "=" + value;
  171. else
  172. _query = "SET GLOBAL " + variable + "='" + value + "'";
  173.  
  174. return executeSqlCommand2(host,_query);
  175. }
  176.  
  177. function mySleep(host, time)
  178. {
  179. _query = "SELECT SLEEP(" + time + ")";
  180. return executeSqlCommand(host, _query);
  181. }
Add Comment
Please, Sign In to add comment