2 Replies Latest reply on May 30, 2014 9:14 AM by Filippe Spolti

    RHQ CLI Script

    Filippe Spolti Novice

      Hello guys.

       

      I'm have this CLI script that is triggered when resources goes down:

       

      resourceId = alert.alertDefinition.resource.id;

       

      //rid = ProxyFactory.getResource(resourceId);

      rid = ResourceManager.getResource(resourceId)

       

       

      exporter.setTarget('raw', '/home/spolti/teste.out')

      exporter.write(rid)

      java.lang.Runtime.getRuntime().exec('/opt/rhq-server-4.10.0/alert-scripts/restart-jboss.sh ')

       

       

      As result of this, I have:

      [root@v-rhqserver bin]# cat /home/spolti/teste1.out

      Resource:

                                     id: 22062

                                   name: AS (127.0.0.1:9990)

                                version: 7.1.1.Final

                    currentAvailability: DOWN

                           resourceType: JBossAS7 Standalone Server

                                  agent: null

                       alertDefinitions: null

                               ancestry: 10008_:_22051_:_localhost

                 autoGroupBackingGroups: null

                           availability: null

                         childResources: null

                              connected: true

                 contentServiceRequests: null

            createChildResourceRequests: null

                                  ctime: 1399511659521

                 deleteResourceRequests: null

                            description: 127.0.0.1

                       driftDefinitions: null

                           eventSources: null

                         explicitGroups: null

                         implicitGroups: null

                installedPackageHistory: null

                      installedPackages: null

                        inventoryStatus: COMMITTED

                                  itime: 1399511911861

                               location:

                             modifiedBy: spolti

                                  mtime: 1400247433701

                     operationHistories: null

                         parentResource: null

          parentResourceWithoutAncestry:

                    pluginConfiguration: Configuration[id=65118]

             pluginConfigurationUpdates: null

                         productVersion: null

                                  repos:

                  resourceConfiguration: Configuration[id=66228]

           resourceConfigurationUpdates: null

                         resourceErrors: null

                            resourceKey: hostConfig: /opt/jboss-as-7.1.1.Final/standalone/configuration/standalone.xml

                          resourceRepos: null

                              schedules: null

                                   tags: null

                                   uuid: ea574390-bc49-48a1-a94c-b2684bb25dd3

       

       

      My Problem is, i wanna filter the descritption field value (description: 127.0.0.1)

       

      and pass as parameter to restart script:

       

      For example:

       

      resourceId = alert.alertDefinition.resource.id;

       

      //rid = ProxyFactory.getResource(resourceId);

      rid = ResourceManager.getResource(resourceId)

       

       

      exporter.setTarget('raw', '/home/spolti/teste.out')

      exporter.write(rid)

      ip = filterDescription ///////how to filter it?

      java.lang.Runtime.getRuntime().exec('/opt/rhq-server-4.10.0/alert-scripts/restart-jboss.sh  ' + ip)

       

       

      Any help is appreciate.

      Thanks.

        • 1. Re: RHQ CLI Script
          Lukas Krejci Apprentice

          What you see written out to the file are actual properties (in the javascript sense) of the resource object, so you don't really need to filter anything. Also, the alertdefinition object already has the resource object attached to it so you don't have to reload it.

           

          In another words, I'd do it like this:

           

          java.lang.Runtime.getRuntime().exec('/opt/rhq-server-4.10.0/alert-scripts/restart-jboss.sh ' + alert.alertDefinition.resource.description);

          1 of 1 people found this helpful
          • 2. Re: RHQ CLI Script
            Filippe Spolti Novice

            Yes, was exactly what I did.

            Thanks.