12 Replies Latest reply on Jul 13, 2015 1:40 PM by Yanick Girouard

    Need to fetch list of all jobs in Bladelogic

    Priyanka Sinha

      I need a fetch a list of all jobs (in specific jobs folder) created by specific users. Please suggest a blcli so as to accomplish this task

        • 2. Re: Need to fetch list of all jobs in Bladelogic
          Yanick Girouard

          This requires you to provide the group the job is in. If he wants to list all jobs, no luck...

           

          You could try this with BLAdmins tough:

           

          blcli_execute Sql executeSqlCommand "select name from job where is_deleted=1 and is_latest_version=1 and is_saved_explicitly=1"

           

          That will return a resultset in XML and you can parse the value field of each line as you wish...

           

          If you have direct SQL access, just dump the jobs using that query.

          • 3. Re: Need to fetch list of all jobs in Bladelogic
            Bill Robinson

            'list of all jobs (in specific jobs folder) created by specific users' would seem to imply the folders are known ?

            • 4. Re: Need to fetch list of all jobs in Bladelogic
              Priyanka Sinha

              Bill my exact requirement is to fetch all the jobs inside different groups Example: If there is a job folder "A" having sub groups a1,a2 .Similarly a folder "B" having sub groups b1,b2.

               

              Please help me with blcli command which could fetch all this data

              • 5. Re: Need to fetch list of all jobs in Bladelogic
                Priyanka Sinha

                I need information for a1,a2,b1 and b2

                • 6. Re: Need to fetch list of all jobs in Bladelogic
                  Bill Robinson

                  The command i gave you should work.

                  • 7. Re: Need to fetch list of all jobs in Bladelogic
                    Greg Wojan

                    Is there a way to recursively list the contents of subfolders?

                    • 8. Re: Need to fetch list of all jobs in Bladelogic
                      Yanick Girouard

                      Not with a single blcli command ... and you'd need a recursive loop to do it. That's why I suggested SQL instead... but then you'll also need to join in a custom SQL view that you'll need to create to get the full path of the group you want to list the jobs under for... I created such a view, and here's the code:

                       

                      SQL Server:

                      SET ANSI_NULLS ON
                      GO
                      
                      
                      SET QUOTED_IDENTIFIER ON
                      GO
                      
                      
                      
                      
                      
                      
                      CREATE VIEW  [dbo].[v_blgroup_paths]
                      AS
                      WITH group_paths (group_id, group_path)
                      AS
                      (
                      -- Anchor member definition
                          SELECT g.group_id, cast('/'+g.name as varchar(max)) as group_path
                          FROM dbo.blgroup AS g
                          WHERE parent_group_id=0
                          UNION ALL
                      -- Recursive member definition
                          SELECT g.group_id, cast(group_path + '/' + g.name as varchar(max))
                          FROM dbo.blgroup AS g
                          INNER JOIN group_paths AS gp
                              ON g.parent_group_id = gp.group_id
                      )
                      -- Statement that executes the CTE
                      SELECT group_id, group_path
                      FROM group_paths
                      
                      
                      GO
                      
                      
                      

                       

                      Oracle:

                      CREATE VIEW V_BLGROUP_PATHS
                      AS WITH group_paths (group_id, group_path)
                      AS
                      (SELECT g.group_id, cast('/' || g.name as varchar2(1000)) AS group_path
                        FROM blgroup g
                        WHERE parent_group_id=0
                        UNION ALL
                        SELECT g.group_id, cast(group_path || '/' || g.name as varchar2(1000))
                        FROM blgroup g
                        INNER JOIN group_paths gp
                        ON g.parent_group_id = gp.group_id
                      )
                      SELECT group_id, group_path
                      FROM group_paths;
                      
                      
                      

                       

                      Then you can use this query:

                       

                      select * from job j
                      inner join v_blgroup_paths g on g.group_id = j.group_id
                      inner join bluser u on u.user_id = j.created_by_user_id
                      where g.group_path like '/Jobs/Path/To/Parent/Folder/%' and u.name = 'Name of user account'
                      and j.is_latest_version=1 and j.is_deleted=0 and j.is_saved_explicitly=1
                      
                      
                      

                       

                      Feel free to wrap this inside the executeSqlCommand blcli I mentioned above. The only tricky part if you do this, is to loop through each line of result to extract the values you need, because it's gonna be in XML.

                      • 9. Re: Need to fetch list of all jobs in Bladelogic
                        Priyanka Sinha

                        Bill I tried above provided command but its only providing jobs that are directly under job group but not the sub group names that are inside it.

                        Taking an Example: Hierarchy is Inside Database parent group we are having sub folders I want to list all the subfolders not contents of sub folders

                        • 10. Re: Need to fetch list of all jobs in Bladelogic
                          Yanick Girouard

                          That's what I stated before... There's no way to recursively list jobs contained within a certain folder tree, because the command requires the full path of a group and will only list the jobs directly under it. Doing this in blcli would require a recursive that walks through all folders to list jobs contained in each level, and woul dtake forever to run if you have a lot of groups.

                           

                          I'm afraid the SQL method using the custom view I posted is the only one that will give you what you need.

                          • 11. Re: Need to fetch list of all jobs in Bladelogic
                            Bill Robinson

                            there's an unreleased blcli that will do it:  findAllByGroupId w/ an option to recurse or not..so:

                             

                            blcli_execute Job findAllByGroupId ${groupId} true

                            blcli_execute Job getDBKey

                            blcli_execute Utility setTargetObject

                            blcli_execute Utility listPrint

                            blcli_storeenv jobKeys

                             

                            ...

                            • 12. Re: Need to fetch list of all jobs in Bladelogic
                              Yanick Girouard

                              Actually Bill, although this does list the DBKeys of jobs contained within a parent folder, it doesn't provide what the poster is looking for, which is all jobs within a folder path that were created by a specific user. As far as I can see there is no way to do that even with the unreleased commands is there?

                               

                              I have modified my response above to include a join and filters to return jobs created by a certain user. The query still requires my custom view, but that's the only way to retrieve jobs within a full path since the group_id field only refers to the immediate parent group, and not the whole path.

                               

                              I'm afraid there is no way to do what the poster wants using only blcli.