sidetrak

Update Related Children

May 1st, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Name: Update Related Children
  3. Table: Configuration Item [cmdb_ci]
  4. Order: 100
  5. When: after
  6. Insert: true
  7. Update: true
  8. Condition: current.supported_by.changes() || current.support_group.changes() || current.install_status.changes() || current.u_substatus.changes() || current.u_used_for.changes()
  9. */
  10. //change related references to new status
  11. updateRelChildren();
  12. updateNetworkAdapters();
  13. updateWindowsService();
  14.  
  15. //remove unneeded references
  16. if (current.install_status == 6 || current.install_status == 7) {
  17.    removeSoftware();
  18.    removeProcesses();
  19.    removeTCPCon();
  20.    removeTCPHalfCon();
  21.    if (current.install_status == 6)
  22.    removeWindowsService();
  23. }
  24.  
  25. function updateRelChildren(){
  26.    //Look for CMDB relations for the current CI
  27.    var rel1 = new GlideRecord('cmdb_rel_ci');
  28.    rel1.addQuery('child.sys_id', current.sys_id);
  29.    rel1.query();
  30.    while(rel1.next()) {
  31.       //Find child CMDB relationships and update
  32.       var child1 = new GlideRecord('cmdb_ci');
  33.       child1.addQuery('sys_id', rel1.parent.sys_id);
  34.       child1.addQuery('sys_class_name','IN','cmdb_ci_web_site,cmdb_ci_web_service,cmdb_ci_web_server,cmdb_ci_db_mssql_instance');
  35.       child1.query();
  36.       while(child1.next()) {
  37.          child1.support_group = current.support_group;
  38.          child1.supported_by = current.supported_by;
  39.          child1.install_status = current.install_status;
  40.          child1.u_substatus = current.u_substatus;
  41.          child1.u_used_for = current.u_used_for;
  42.          child1.update();
  43.          //If class_name is a db instance, update children catalogs
  44.          if (child1.sys_class_name == 'cmdb_ci_db_mssql_instance') {
  45.             var rel2 = new GlideRecord('cmdb_ci_db_catalog');
  46.             rel2.addQuery('database_instance', rel1.parent);
  47.             rel2.query();
  48.             while(rel2.next()) {
  49.                rel2.support_group = current.support_group;
  50.                rel2.supported_by = current.supported_by;
  51.                rel2.install_status = current.install_status;
  52.                rel2.u_substatus = current.u_substatus;
  53.                rel2.u_used_for = current.u_used_for;
  54.                rel2.update();
  55.                //gs.addInfoMessage('Upstream relation updated in table ' + rel2.sys_class_name);
  56.             }
  57.          }
  58.       }
  59.    }
  60.    //gs.addInfoMessage('Upstream relation updated in table ' + child1.sys_class_name);
  61. }
  62.  
  63. function updateNetworkAdapters(){
  64.    var net = new GlideRecord("cmdb_ci_network_adapter");
  65.    net.addQuery("cmdb_ci.sys_id", current.sys_id);
  66.    net.query();
  67.    while (net.next()) {
  68.       net.install_status = current.install_status;
  69.       net.u_substatus = current.u_substatus;
  70.       net.u_used_for = current.u_used_for;
  71.       net.update();
  72.    }
  73. }
  74.  
  75. function updateWindowsService(){
  76.    var gr = new GlideRecord("cmdb_ci_windows_service");
  77.    gr.addQuery("cmdb_ci.sys_id", current.sys_id);
  78.    gr.query();
  79.    while (gr.next()) {
  80.       gr.install_status = current.install_status;
  81.       gr.u_substatus = current.u_substatus;
  82.       gr.u_used_for = current.u_used_for;
  83.       gr.update();
  84.    }
  85. }
  86.  
  87. function removeSoftware() {
  88.    var gr = new GlideRecord("cmdb_software_instance");
  89.    gr.addQuery("installed_on.sys_id", current.sys_id);
  90.    gr.query();
  91.    while(gr.next()) {
  92.       gr.deleteRecord();
  93.    }
  94. }
  95.  
  96. function removeProcesses() {
  97.    var gr = new GlideRecord("cmdb_running_process");
  98.    gr.addQuery("computer.sys_id", current.sys_id);
  99.    gr.query();
  100.    while(gr.next()) {
  101.       gr.deleteRecord();
  102.    }
  103. }
  104.  
  105. function removeTCPCon() {
  106.    var gr = new GlideRecord("cmdb_tcp_connection");
  107.    gr.addQuery("computer.sys_id", current.sys_id);
  108.    gr.query();
  109.    while(gr.next()) {
  110.       gr.deleteRecord();
  111.    }
  112. }
  113.  
  114. function removeTCPHalfCon() {
  115.    var gr = new GlideRecord("cmdb_tcp_half");
  116.    gr.addQuery("computer.sys_id", current.sys_id);
  117.    gr.query();
  118.    while(gr.next()) {
  119.       gr.deleteRecord();
  120.    }
  121. }
  122.  
  123. function removeWindowsService(){
  124.    var gr = new GlideRecord("cmdb_ci_windows_service");
  125.    gr.addQuery("cmdb_ci.sys_id", current.sys_id);
  126.    gr.query();
  127.    while (gr.next()) {
  128.       gr.deleteRecord();
  129.    }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment