DX NetOps

Expand all | Collapse all

Spectrum Export Help

  • 1.  Spectrum Export Help

    Posted Mar 26, 2014 05:30 PM

    Hello All,

    We are trying to export spectrum database in CSV format, But we need only some attributes like, name, ipaddress, manufacture, condition, model class and model type.  We need to send this csv file to other application at scheduled interval.  We tried to use restful API, but it is displaying in XML format. Is there any way that we can fetch only selected attributes from spectrum database in CSV format? Kindly help !!!!

     

     

     



  • 2.  RE: Spectrum Export Help

    Posted Mar 26, 2014 05:58 PM

    This can be done fairly easily with the Command Line Interface (CLI). For each device model, extract the information and save it to a delimited text file. This can be scripted and then schedule the script to run. Reference the Command Line Interface Guide.

    The following is an example. Use at your own risk :-)

    #!/bin/sh
    CLISESSID=$$
    export CLISESSID
    rm ModelInfo.out
    echo "Name:IP Address:Manufacturer:Condition:Model Class:Model Type" > ModelInfo.out
    ./connect > /dev/null 2>&1
    for MH in `./show devices | grep -v MHandle | awk '{ print $1}'`
    do
    ./current mh=$MH > /dev/null 2>&1
    NAME=`./show attributes attr=0x1006e | grep -v Iid | awk '{ print $3 }'`
    IPADDR=`./show attributes attr=0x12d7f | grep -v Iid | awk '{ print $3 }'`
    MAN=`./show attributes attr=0x10032 | grep -v Iid | awk '{ print $3 }'`
    COND=`./show attributes attr=0x1000a | grep -v Iid | awk '{ print $3 }'`
    CLASS=`./show attributes attr=0x11ee8 | grep -v Iid | awk '{ print $3 }'`
    TYPE=`./show attributes attr=0x10000 | grep -v Iid | awk '{ print $3 }'`
    echo $NAME":"$IPADDR":"$MAN":"$COND":"$CLASS":"$TYPE >> ModelInfo.out
    done
    ./disconnect > /dev/null 2>&1



  • 3.  RE: Spectrum Export Help

    Posted Apr 02, 2014 04:38 PM

    Hello Joseph,

    Thank you so much for your quick solution. I have modified the script somewhat and it works perfectly.

    1. For model_Class ( 0x11ee8 ), i am getting integer value something like 9,12, ...  I need to get result like Pingable or Workstation-Server. 

    2. I can see entries in the VNMSHD.OUT log whenever the script is running. 

    Can you help me ?


     

     



  • 4.  RE: Spectrum Export Help

    Posted Apr 02, 2014 04:48 PM

    you can use Restful API to get model_class enums

     http://servername/spectrum/restful/attribute/0x11ee8/enums



  • 5.  RE: Spectrum Export Help

    Posted Apr 02, 2014 06:14 PM

    Daniel,

    Instead of numbers, i need to get the value for a model directly from database. Is there any way ?



  • 6.  RE: Spectrum Export Help

    Posted Apr 03, 2014 01:16 PM

    You're starting to get into the realm of shell/perl scripting because you're having to interpret data being pulled from the database. In the case of those values, that's what is actually stored in the database - not the tags (pingable, workstation-server, etc.)



  • 7.  RE: Spectrum Export Help

    Posted Apr 03, 2014 11:24 PM

    Thanks for the reply. Can someone let me know why VNMSHD.OUT is increasing when i run the script.



  • 8.  Re: RE: Spectrum Export Help

    Posted Apr 13, 2015 11:25 AM

    I tried the provided Script and only get header info, no data.  Any other suggestions?



  • 9.  Re: Spectrum Export Help

    Posted Apr 13, 2015 03:14 PM

    Why don't you just extract the data from the XML. This is how I do it. You can choose XML or JSON as well if JSON is what you prefer. There are lots of modules for example perl, which deal with making this easier.

     

    Unfortunately there is no easy way and you will need to make effort as this isn't something that is available out of the box. I'm not sure about SRM and it's capabilities but my experience is that the API gives you more flexibility and we do everything using REST now (well, all that we can.) There are still a few things you can't do but I'm sure CA will sort these things out soon.



  • 10.  Re: RE: Spectrum Export Help

    Posted Apr 13, 2015 03:38 PM

    Frank,

    How can I schedule an export to happen once a week?  Is there a script I can run via CLI?



  • 11.  Re: Spectrum Export Help

    Posted Apr 14, 2015 06:14 AM

    I use mainly Linux, so you can just use cron (edit /etc/crontab file) to schedule it to run when you want. You will need to write the script and cron it.

     

    I think windows has the 'at' command. You would have to read up on this though, as I haven't worked on a Windows server in eons!



  • 12.  Re: Spectrum Export Help

    Posted Apr 15, 2015 05:01 AM

    XML POST code is:

     

    <?xml version="1.0" encoding="UTF-8"?>
    
    
    <rs:model-request throttlesize="1000"
      xmlns:rs="http://www.ca.com/spectrum/restful/schema/request"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.ca.com/spectrum/restful/schema/request ../../../xsd/Request.xsd">
    
    
      <rs:target-models>
        <rs:models-search>
          <rs:search-criteria
               xmlns="http://www.ca.com/spectrum/restful/schema/filter">
            <devices-only-search/>
            <filtered-models>
                <greater-than>
                  <attribute id="0x129fa">
                    <value>0x000000</value>
                  </attribute>
                </greater-than>
            </filtered-models>
          </rs:search-criteria>
        </rs:models-search>
      </rs:target-models>
    
    
      <rs:requested-attribute id="0x1006e"/>
      <rs:requested-attribute id="0x12d7f"/>
      <rs:requested-attribute id="0x10032"/>
      <rs:requested-attribute id="0x1000a"/>
      <rs:requested-attribute id="0x11ee8"/>
      <rs:requested-attribute id="0x10000"/>
    
    
    </rs:model-request>
    
    
    
    

     

    You can just extract the info you need:

     

    <model mh="0x1f141a0"><attribute id="0x1006e">kdevs66</attribute><attribute id="0x12d7f">1.1.1.1</attribute><attribute id="0x10032"></attribute><attribute id="0x1000a">0</attribute><attribute id="0x11ee8">12</attribute><attribute id="0x10000">Pingable</attribute></model>

     

    Each device's info is encompassed in <model> </model> tags.

     

    You can do something like:

     

    # Look through XML to get models
    while ($restXml =~ /<model mh=\"(0x.*?)\">(.*?)<\/model>/g) {
    ($mh, $attribList) = ($1, $2);
    
      # Now we iterate through each of the attributes
      while ($attribList =~ /<attribute id=\"(0x.*?)\"(.*?\/.*?)>/g) {
    
        ($attr, $val) = ($1, $2);
    
        # We need to cater for when the model doesn't have some attributes, eg. Pingable devices don't have community name and will return 'NoSuchAttribute'.
        if ($val =~ / error=\"NoSuchAttribute\"\//) {
          $val = '';
        } elsif ($val =~ />(.*?)<\/attribute/) {
          $val = $1;
        }
    
        print "Attribute '$attr' is '$val'\n";
    
    }
    
    
    
    

     

    You can also use:

     

    http://<SERVER>:<PORT>/spectrum/restful/devices?attr=0x1006e&attr=0x12d7f

     

    Which might be quicker if you want all devices on all servers. I normally use POST XML because you have more control over what devices you want to return. E.g. Instead of all devices, you can say for example all devices which contain the phrase 'core' in the name.

    You can just add &attr= for additional attributes you may want to include.

     

    Hope this helps