CMDBuild Forum

basic-connector and related items

I am trying to figure out how to import related items from OCS Inventory. I have my devices being imported successfully, but when I try and import monitors and tie them to their related devices the monitors end up being imported as PCs and no relationship is created (additionally until I made the Code unique in the class, I was ending up with three copies of each monitor every time I ran the connector.sh script). I think I did everything in the docs, the one thing I don't understand is the statement "In the case of master class-related cards, as in the case of Monitor, the previous tag pair, with their attributes, must always be specified." 

Given the cmbuild-schema.xml and transform.xml below, can anyone tell me what I'm missing? I created a PcMonitor domain that maps 1:N from PC to Monitor, I assumed that would handle the relationship mapping for me.

cmbuild-schema.xml:

<?xml version="1.0"?> 

<CMDBUILD> 

<PC> 

<Code /> 

<Description /> 

<SerialNumber /> 

<Brand />

<Model />

<RAM /> 

<IPAddress /> 

<CPUNumber /> 

<CPUSpeed /> 

</PC> 

<Monitor>

<Code /> 

<Description />

<SerialNumber /> 

<Brand />

<Model />

</Monitor>

 

</CMDBUILD>

transform.xml:

<?xml version="1.0" encoding="UTF-8"?> 

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform

version="1.0"> 

<xsl:output method="xml" version="1.0" encoding="UTF-8" 

indent="yes" /> 

<xsl:template match="/"> 

<CMDBUILD> 

<xsl:apply-templates /> 

</CMDBUILD> 

</xsl:template> 

<xsl:template match="*"> 

<xsl:apply-templates /> 

</xsl:template> 

<xsl:template match="text()"></xsl:template> 

<xsl:template match="/inventory/device"> 

<PC key="Code"> 

<Code> 

<xsl:value-of select="./UUID" /> 

</Code> 

<Description> 

<xsl:value-of select="./NAME" /> 

</Description> 

<Brand> 

<xsl:value-of select="./SMANUFACTURER" /> 

</Brand> 

<Model> 

<xsl:value-of select="./SMODEL" /> 

</Model> 

<SerialNumber>

<xsl:value-of select="./SSN" /> 

</SerialNumber> 

<IPAddress> 

<xsl:value-of select="./IPADDR" /> 

</IPAddress> 

<RAM> 

<xsl:value-of select="sum(/inventory/memory/CAPACITY)" /> 

</RAM> 

<CPUNumber> 

<xsl:value-of select="./PROCESSORN" /> 

</CPUNumber> 

<CPUSpeed> 

<xsl:value-of select="./PROCESSORS" /> 

</CPUSpeed> 

</PC> 

</xsl:template> 

<xsl:template match="/inventory/monitor"> 

<Monitor key="Code"> 

<Code> 

<xsl:value-of select="./ID" /> 

</Code> 

<Description> 

<xsl:value-of select="./DESCRIPTION" /> 

</Description> 

<SerialNumber> 

<xsl:value-of select="./SERIAL" /> 

</SerialNumber> 

<Brand> 

<xsl:value-of select="./MANUFACTURER" /> 

</Brand> 

<Model> 

<xsl:value-of select="./CAPTION" /> 

</Model> 

</Monitor> 

</xsl:template> 

<xsl:template match="/CMDBUILD/PC"> 

<PC key="Code"> 

<xsl:attribute name="objid"> 

        <xsl:value-of select="./@objid" /> 

      </xsl:attribute> 

<Code> 

<xsl:value-of select="./Code" /> 

</Code> 

<Description> 

<xsl:value-of select="./Description" /> 

</Description> 

<Brand> 

<xsl:value-of select="./Brand" /> 

</Brand> 

<Model> 

<xsl:value-of select="./Model" /> 

</Model> 

<SerialNumber> 

<xsl:value-of select="./SerialNumber" /> 

</SerialNumber> 

<IPAddress> 

<xsl:value-of select="./SerialNumber" /> 

</IPAddress> 

<RAM> 

<xsl:value-of select="./RAM" /> 

</RAM> 

<CPUNumber> 

<xsl:value-of select="./CPUNumber" /> 

</CPUNumber> 

<CPUSpeed> 

<xsl:value-of select="./CPUSpeed" /> 

</CPUSpeed> 

</PC> 

</xsl:template> 

<xsl:template match="/CMDBUILD/Monitor"> 

<Monitor domain="PcMonitor" domaindirection="directed" identifiers="Code">

<xsl:attribute name="objid">

<xsl:value-of select="./@objid" />

</xsl:attribute>

<Code>

<xsl:value-of select="./Code" />

</Code>

<Description>

<xsl:value-of select="./Description" />

</Description>

<SerialNumber>

<xsl:value-of select="./SerialNumber" />

</SerialNumber>

<Brand>

<xsl:value-of select="./Brand" />

</Brand>

<Model>

<xsl:value-of select="./Model" />

</Model>

</Monitor> 

</xsl:template> 

 

 

</xsl:stylesheet>

 

 

To follow up on my own post, it looks like half the secret is having the domain and domain direction in both the origination and destination blocks. For example:
        <xsl:template match="/inventory/monitor"> 
                <Monitor domain="PCMonitor" domaindirection="directed" identifiers="Code" key="Code">
and
        <xsl:template match="/CMDBUILD/Monitor"> 
                <Monitor domain="PCMonitor" domaindirection="directed" identifiers="Code" key="Code">
 
From looking at the RFC example, it looks like the relationship has to be defined in the xpdl file and then imported. I'm trying to dig through the RFC xpdl file to see if I can figure out the magic to tie my computers and monitors together. From there I figure I will have to write a separate activity for each relationship. 
 
Does anyone have this working who can share an example?
 
Previously Dan Rich wrote:

I am trying to figure out how to import related items from OCS Inventory. I have my devices being imported successfully, but when I try and import monitors and tie them to their related devices the monitors end up being imported as PCs and no relationship is created (additionally until I made the Code unique in the class, I was ending up with three copies of each monitor every time I ran the connector.sh script). I think I did everything in the docs, the one thing I don't understand is the statement "In the case of master class-related cards, as in the case of Monitor, the previous tag pair, with their attributes, must always be specified." 

 

 

To continue answering my own question (but I still need help)...
 
I'm assuming that the relationships have to be built via. TaskScripts in the xpdl file. While I found the methods that are available in the Workflow documentation, I'm not entirely clear on host to make use of them.
 
How do I access the non-card data from an incoming SOAP request? Let's say I have data for a monitor that was created by this SOAP request:
<ExternalSync>
  <cardList>
    <Monitor identifiers="Code" domaindirection="directed" domain="PCMonitor">
      <Code>71104</Code>
      <Description>HWP.2954.00000000 (27/2012)</Description>
      <SerialNumber>CN42270ZRV</SerialNumber>
      <Brand>Hewlett Packard</Brand>
      <Model>HP ZR2440w</Model>
    </Monitor>
  </cardList>
<cardMaster>
  <masterCardId>1847</masterCardId>
  <masterClassName>PC</masterClassName>
</cardMaster>
<action>create</action>
</ExternalSync>
 
I know that the call I need to make in the script is something like: 'cmdb.newRelation(domain).withCard1("PC", MasterCardID.intValue()).withCard2(ProcessClass, ProcessID.intValue()).create()', where 'domain' is teh domain in the XML above and 'MasterCardID' is a reference to the masterCardId. However, from a look through the available methods I don't see a way to get that info for the current card being processed in the workflow. What am I missing?
 
I'm assuming someone has done this??!?
 
Previously Dan Rich wrote:
To follow up on my own post, it looks like half the secret is having the domain and domain direction in both the origination and destination blocks. For example:
        <xsl:template match="/inventory/monitor"> 
                <Monitor domain="PCMonitor" domaindirection="directed" identifiers="Code" key="Code">
and
        <xsl:template match="/CMDBUILD/Monitor"> 
                <Monitor domain="PCMonitor" domaindirection="directed" identifiers="Code" key="Code">
 
From looking at the RFC example, it looks like the relationship has to be defined in the xpdl file and then imported. I'm trying to dig through the RFC xpdl file to see if I can figure out the magic to tie my computers and monitors together. From there I figure I will have to write a separate activity for each relationship. 
 
Does anyone have this working who can share an example?
 
Previously Dan Rich wrote:

I am trying to figure out how to import related items from OCS Inventory. I have my devices being imported successfully, but when I try and import monitors and tie them to their related devices the monitors end up being imported as PCs and no relationship is created (additionally until I made the Code unique in the class, I was ending up with three copies of each monitor every time I ran the connector.sh script). I think I did everything in the docs, the one thing I don't understand is the statement "In the case of master class-related cards, as in the case of Monitor, the previous tag pair, with their attributes, must always be specified."