Menu

modify Server class

Alex PL
2012-01-31
2012-12-19
  • Alex PL

    Alex PL - 2012-01-31

    Hi all,
    I need some advice to customize my iTop cmdb, Configuration Management

    I need to add all servers in my org both physical and virtual. So, we need to know where a virtual server is hosted (in which physical server).

    One approach to this is a modification on iTop to allow Server class be dependent on a Application Instance so, the data will result:

    server  -*depends on*-> application instance -*depends on*-> server
    guest server -> vmware/xe/virtual pc instance -> host server

    If the host server should be stopped or the vmware install should be patched, I'll get the list of affected virtual-servers

    I need some guidance in the process of iTop modification. After modifying the server class I must reinstall iTop? How do you manage virtual and physical servers?

     
  • Bruno Bonfils

    Bruno Bonfils - 2012-01-31

    Hello,

    look at the Extending and Integrating iTop forum, I post a way to add two attributes:
    - one for the type of host (physical, ESX, domU, etc)
    - one for the physical parent host

    Hope it will helpfull

     
  • Dylan Barlett

    Dylan Barlett - 2012-01-31

    I created child classes of Server called PhysicalServer and VirtualServer. PhysicalServer has a new tab, VM Guests. VirtualServer has a new field, VM Host. Impact and dependency analysis behave as you would expect.

    I modified two files:
    /modules/itop-config-mgmt-1.0.0/model.itop-config-mgmt.php
    /modules/itop-config-mgmt-1.0.0/en.dict.itop-config-mgmt.php
    and created two new images:
    /trunk/iTop/modules/itop-config-mgmt-1.0.0/images/physicalserver.png
    /trunk/iTop/modules/itop-config-mgmt-1.0.0/images/virtualserver.png

    /modules/itop-config-mgmt-1.0.0/model.itop-config-mgmt.php

    class PhysicalServer extends Server
    {
        public static function Init()
        {
            $aParams = array
            (
                "category" => "bizmodel,searchable,configmgmt",
                "key_type" => "autoincrement",
                "name_attcode" => "name",
                "state_attcode" => "",
                "reconc_keys" => array("name","org_id","owner_name","location_id","location_name"),
                "db_table" => "physicalserver",
                "db_key_field" => "id",
                "db_finalclass_field" => "",
                "icon" => "../modules/itop-config-mgmt-1.0.0/images/physicalserver.png",
            );
            MetaModel::Init_Params($aParams);
            MetaModel::Init_InheritAttributes();
            MetaModel::Init_AddAttribute(new AttributeLinkedSet("vm_guests", array("linked_class"=>"VirtualServer", "ext_key_to_me"=>"vm_host_instance_id", "allowed_values"=>null, "count_min"=>0, "count_max"=>0, "depends_on"=>array())));
            MetaModel::Init_SetZListItems('details', array('name', 'status', 'org_id', 'importance', 'brand', 'model', 'serial_number', 'asset_ref', 'purchase_date', 'warranty_end', 'description', 'location_id', 'location_details', 'management_ip', 'default_gateway', 'cpu', 'ram', 'hdd', 'os_family', 'os_version', 'contact_list', 'document_list', 'solution_list', 'contract_list', 'ticket_list', 'nwinterface_list', 'application_list', 'patch_list', 'vm_guests'));
            MetaModel::Init_SetZListItems('advanced_search', array('name', 'status', 'org_id', 'importance', 'brand', 'model', 'serial_number', 'asset_ref', 'description', 'location_id', 'location_details', 'management_ip', 'default_gateway', 'cpu', 'ram', 'hdd', 'os_family', 'os_version'));
            MetaModel::Init_SetZListItems('standard_search', array('name', 'status', 'org_id', 'importance', 'brand', 'model', 'serial_number', 'asset_ref', 'location_id', 'management_ip', 'default_gateway', 'os_family', 'os_version'));
            MetaModel::Init_SetZListItems('list', array('status', 'org_id', 'importance', 'brand', 'model', 'location_id', 'os_family'));
        }
        public static function GetRelationQueries($sRelCode)
        {
            switch ($sRelCode)
            {
                case "impacts":
                $aRels = array(
                    "guests" => array("sQuery"=>"SELECT VirtualServer AS guest WHERE guest.vm_host_instance_id = :this->id", "bPropagate"=>true, "iDistance"=>5),
                    "applications" => array("sQuery"=>"SELECT SoftwareInstance AS app WHERE app.device_id = :this->id", "bPropagate"=>true, "iDistance"=>5),
                    "connected_devices" => array("sQuery"=>"SELECT Device AS dev JOIN NetworkInterface AS if1 ON if1.device_id = dev.id JOIN NetworkInterface AS if2 ON if2.connected_if = if1.id WHERE if2.device_id = :this->id AND if2.link_type='downlink'", "bPropagate"=>true, "iDistance"=>5),
                );
                return array_merge($aRels, parent::GetRelationQueries($sRelCode));
                break;
    
                case "depends on":
                $aRels = array(
                    "connected_devices" => array("sQuery"=>"SELECT Device AS dev JOIN NetworkInterface AS if1 ON if1.device_id = dev.id JOIN NetworkInterface AS if2 ON if2.connected_if = if1.id WHERE if2.device_id = :this->id AND if2.link_type='uplink'", "bPropagate"=>true, "iDistance"=>5),
                );
                return array_merge($aRels, parent::GetRelationQueries($sRelCode));
                break;
                default:
                return parent::GetRelationQueries($sRelCode);           
            }
        }
    }
    class VirtualServer extends Server
    {
        public static function Init()
        {
            $aParams = array
            (
                "category" => "bizmodel,searchable,configmgmt",
                "key_type" => "autoincrement",
                "name_attcode" => "name",
                "state_attcode" => "",
                "reconc_keys" => array("name","org_id","owner_name","location_id","location_name"),
                "db_table" => "virtualserver",
                "db_key_field" => "id",
                "db_finalclass_field" => "",
                "icon" => "../modules/itop-config-mgmt-1.0.0/images/virtualserver.png",
            );
            MetaModel::Init_Params($aParams);
            MetaModel::Init_InheritAttributes();
            MetaModel::Init_AddAttribute(new AttributeExternalKey("vm_host_instance_id", array("targetclass"=>"PhysicalServer", "jointype"=>null, "allowed_values"=>new ValueSetObjects('SELECT PhysicalServer WHERE org_id = :this->org_id'), "sql"=>"vm_host_instance_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array("org_id"))));
            MetaModel::Init_SetZListItems('details', array('name', 'status', 'org_id', 'importance', 'brand', 'model', 'serial_number', 'asset_ref', 'purchase_date', 'warranty_end', 'description', 'vm_host_instance_id', 'location_id', 'location_details', 'management_ip', 'default_gateway', 'cpu', 'ram', 'hdd', 'os_family', 'os_version', 'contact_list', 'document_list', 'solution_list', 'contract_list', 'ticket_list', 'nwinterface_list', 'application_list', 'patch_list'));
            MetaModel::Init_SetZListItems('advanced_search', array('name', 'status', 'org_id', 'importance', 'brand', 'model', 'serial_number', 'asset_ref', 'description', 'location_id', 'location_details', 'management_ip', 'default_gateway', 'cpu', 'ram', 'hdd', 'os_family', 'os_version'));
            MetaModel::Init_SetZListItems('standard_search', array('name', 'status', 'org_id', 'importance', 'brand', 'model', 'serial_number', 'asset_ref', 'location_id', 'management_ip', 'default_gateway', 'os_family', 'os_version'));
            MetaModel::Init_SetZListItems('list', array('status', 'org_id', 'importance', 'brand', 'model', 'location_id', 'os_family'));
        }
        public static function GetRelationQueries($sRelCode)
        {
            switch ($sRelCode)
            {
                case "impacts":
                $aRels = array(
                    "applications" => array("sQuery"=>"SELECT SoftwareInstance AS app WHERE app.device_id = :this->id", "bPropagate"=>true, "iDistance"=>5),
                    "connected_devices" => array("sQuery"=>"SELECT Device AS dev JOIN NetworkInterface AS if1 ON if1.device_id = dev.id JOIN NetworkInterface AS if2 ON if2.connected_if = if1.id WHERE if2.device_id = :this->id AND if2.link_type='downlink'", "bPropagate"=>true, "iDistance"=>5),
                );
                return array_merge($aRels, parent::GetRelationQueries($sRelCode));
                break;
    
                case "depends on":
                $aRels = array(
                    "host" => array("sQuery"=>"SELECT PhysicalServer AS host WHERE host.id = :this->vm_host_instance_id", "bPropagate"=>true, "iDistance"=>5),
                    "connected_devices" => array("sQuery"=>"SELECT Device AS dev JOIN NetworkInterface AS if1 ON if1.device_id = dev.id JOIN NetworkInterface AS if2 ON if2.connected_if = if1.id WHERE if2.device_id = :this->id AND if2.link_type='uplink'", "bPropagate"=>true, "iDistance"=>5),
                );
                return array_merge($aRels, parent::GetRelationQueries($sRelCode));
                break;
                default:
                return parent::GetRelationQueries($sRelCode);           
            }
        }
    }
    

    /modules/itop-config-mgmt-1.0.0/en.dict.itop-config-mgmt.php

    // Class: PhysicalServer
    //
    Dict::Add('EN US', 'English', 'English', array(
        'Class:PhysicalServer' => 'Physical Server',
        'Class:PhysicalServer+' => '',
        'Class:PhysicalServer/Attribute:asset_ref' => 'Rack',
        'Class:PhysicalServer/Attribute:asset_ref+' => 'Rack location',
        'Class:PhysicalServer/Attribute:cpu' => 'CPU',
        'Class:PhysicalServer/Attribute:cpu+' => '',
        'Class:PhysicalServer/Attribute:ram' => 'RAM',
        'Class:PhysicalServer/Attribute:ram+' => '',
        'Class:PhysicalServer/Attribute:hdd' => 'Hard Disk',
        'Class:PhysicalServer/Attribute:hdd+' => '',
        'Class:PhysicalServer/Attribute:os_family' => 'OS Family',
        'Class:PhysicalServer/Attribute:os_family+' => '',
        'Class:PhysicalServer/Attribute:os_version' => 'OS Version',
        'Class:PhysicalServer/Attribute:os_version+' => '',
        'Class:PhysicalServer/Attribute:application_list' => 'Applications',
        'Class:PhysicalServer/Attribute:application_list+' => 'Applications installed on this server',
        'Class:PhysicalServer/Attribute:patch_list' => 'Patches',
        'Class:PhysicalServer/Attribute:patch_list+' => 'Patches installed on this server',
        'Class:PhysicalServer/Attribute:vm_guests' => 'VM Guests',
        'Class:PhysicalServer/Attribute:vm_guests+' => 'Virtual machine guests',
    ));
    //
    // Class: VirtualServer
    //
    Dict::Add('EN US', 'English', 'English', array(
        'Class:VirtualServer' => 'Virtual Server',
        'Class:VirtualServer+' => '',
        'Class:VirtualServer/Attribute:cpu' => 'CPU',
        'Class:VirtualServer/Attribute:cpu+' => '',
        'Class:VirtualServer/Attribute:ram' => 'RAM',
        'Class:VirtualServer/Attribute:ram+' => '',
        'Class:VirtualServer/Attribute:hdd' => 'Hard Disk',
        'Class:VirtualServer/Attribute:hdd+' => '',
        'Class:VirtualServer/Attribute:os_family' => 'OS Family',
        'Class:VirtualServer/Attribute:os_family+' => '',
        'Class:VirtualServer/Attribute:os_version' => 'OS Version',
        'Class:VirtualServer/Attribute:os_version+' => '',
        'Class:VirtualServer/Attribute:application_list' => 'Applications',
        'Class:VirtualServer/Attribute:application_list+' => 'Applications installed on this server',
        'Class:VirtualServer/Attribute:patch_list' => 'Patches',
        'Class:VirtualServer/Attribute:patch_list+' => 'Patches installed on this server',
        'Class:VirtualServer/Attribute:vm_host_instance_id' => 'VM Host',
        'Class:VirtualServer/Attribute:vm_host_instance_id+' => 'Virtual machine host',
    ));
    
     
  • Alex PL

    Alex PL - 2012-02-13

    Thx !
    I will try this as soon as I can.

     
  • M. Brown

    M. Brown - 2012-03-08

    FYI, I've submitted enhancement ticket 537 (https://sourceforge.net/apps/trac/itop/ticket/537) to incorporate Virtualisation, Storage, Blades, and Virtual Networking.  There's a file attached, and it contains full files and diffs against iTop 1.2.1.

    Hope that helps!

    /Mike

     
  • Erwan Taloc

    Erwan Taloc - 2012-03-08

    Hi all
    i'm working on designing a new data model for next release.
    I will have a look at all your posts and will see what can be included in next version

    Cheers

     
  • M. Brown

    M. Brown - 2012-03-08

    etaloc,

    Thanks! I spent the better part of a month working on the code for that (including a lot of time at a white board figuring out the proper relationships between stuff.

    /Mike

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.