Check_MK - WATO Uncheck Service

Remember which checkbox should be always on or off by doubleclick on checkbox under WATO/Services of host.

  1. // ==UserScript==
  2. // @name Check_MK - WATO Uncheck Service
  3. // @namespace http://openuserjs.org/users/ardiman
  4. // @description Remember which checkbox should be always on or off by doubleclick on checkbox under WATO/Services of host.
  5. // @description:de-DE Merkt sich, welches Kontrollkästchen immer ein- oder ausgeschaltet sein soll durch Doppelklick auf das Kontrollkästchen unter WATO/Services of host.
  6. // @grant GM_getValue
  7. // @grant GM_setValue
  8. // @homepage https://github.com/ardiman/userscripts/tree/master/checkmkwatouncheckservice
  9. // @icon https://raw.githubusercontent.com/ardiman/userscripts/master/scriptlogo.gif
  10. // @include */check_mk/wato.py?mode=inventory&host*
  11. // @include */check_mk/wato.py?filled_in=edithost*
  12. // @include */check_mk/wato.py?folder=&host=*&mode=inventory
  13. // @license CC-BY-NC-SA-3.0; https://creativecommons.org/licenses/by-nc-sa/3.0/legalcode
  14. // @license MIT; https://opensource.org/licenses/MIT
  15. // @supportURL https://github.com/ardiman/userscripts/issues
  16. // @version 1.0.5
  17. // @date 2017-11-19
  18. // ==/UserScript==
  19.  
  20. var cmkwatouncheckservice = {
  21. setting: {
  22. bgru: "blue", // background of table cell with automatically unchecked checkbox
  23. bgrc: "purple", // background of table cell with automatically checked checkbox
  24. speeks: false, // show alert if "automatically unchecked/checked" is changed
  25. },
  26.  
  27. init: function() {
  28. // Select checkboxes
  29. var nodes = document.evaluate(
  30. "//span[@class='checkbox']/input[@type='checkbox']",
  31. document,
  32. null,
  33. XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
  34. null);
  35. var uncheckedservices = GM_getValue('cmkwatouncheckedservices','');
  36. var checkedservices = GM_getValue('cmkwatocheckedservices','');
  37. var myUArr = uncheckedservices.split(";");
  38. var myCArr = checkedservices.split(";");
  39. var i = 0;
  40. // Change style of checkboxes (grandparent) and set their dblclick-event
  41. for(var j = 0; j<nodes.snapshotLength; j++) {
  42. var thisNode = nodes.snapshotItem(j);
  43. var thisNodeName = thisNode.name;
  44. var hitU = myUArr.indexOf(thisNodeName);
  45. var hitC = myCArr.indexOf(thisNodeName);
  46. if (hitU !== -1) {
  47. i++;
  48. thisNode.checked = false;
  49. thisNode.parentNode.parentNode.setAttribute('style','background: ' + cmkwatouncheckservice.setting.bgru + ';');
  50. }
  51. if (hitC !== -1) {
  52. i++;
  53. thisNode.checked = true;
  54. thisNode.parentNode.parentNode.setAttribute('style','background: ' + cmkwatouncheckservice.setting.bgrc + ';');
  55. }
  56. thisNode.ondblclick=function(event) {
  57. event.preventDefault();
  58. event.stopPropagation();
  59. if (this.checked) {
  60. cmkwatouncheckservice.changecheck(this,'cmkwatocheckedservices',true,cmkwatouncheckservice.setting.bgrc,'cmkwatouncheckedservices');
  61. } else {
  62. cmkwatouncheckservice.changecheck(this,'cmkwatouncheckedservices',false,cmkwatouncheckservice.setting.bgru,'cmkwatocheckedservices');
  63. }
  64. };
  65. }
  66. return i;
  67. },
  68.  
  69. changecheck: function(ele,whichValue,forMsg,bg,otherValue) {
  70. var myServices = GM_getValue(whichValue,'');
  71. var otherServices = GM_getValue(otherValue,'');
  72. var myArr = myServices.split(";");
  73. var myOtherArr = otherServices.split(";");
  74. var hit = myArr.indexOf(ele.name);
  75. var hitOther = myOtherArr.indexOf(ele.name);
  76. if (hit === -1) {
  77. myServices = myServices + ";" + ele.name;
  78. if (cmkwatouncheckservice.setting.speeks) {
  79. alert("Next page load will set checked=" + forMsg + " for this input.");
  80. }
  81. ele.parentNode.parentNode.setAttribute('style','background: ' + bg + ';');
  82. }
  83. else {
  84. myArr.splice(hit, 1);
  85. myServices = myArr.join(';');
  86. if (cmkwatouncheckservice.setting.speeks) {
  87. alert("Next page load won't change checked status for this input anymore.");
  88. }
  89. ele.parentNode.parentNode.setAttribute('style','background: inherit;');
  90. }
  91. GM_setValue(whichValue,myServices);
  92. if (hitOther !==-1) {
  93. myOtherArr.splice(hit, 1);
  94. otherServices = myOtherArr.join(';');
  95. GM_setValue(otherValue,otherServices);
  96. }
  97. }
  98. };
  99.  
  100. var setchkbx = cmkwatouncheckservice.init();
  101. if (cmkwatouncheckservice.setting.speeks && setchkbx !==0) {
  102. alert("One or more (" + setchkbx + ") checkboxes were set automatically. Please save this configuration.");
  103. }
  104.