@@ -33,7 +33,9 @@ class Foreman(Plugin):
3333 PluginOpt ('proxyfeatures' , default = False ,
3434 desc = 'collect features of smart proxies' ),
3535 PluginOpt ('puma-gc' , default = False ,
36- desc = 'collect Puma GC stats' )
36+ desc = 'collect Puma GC stats' ),
37+ PluginOpt ('content-views' , default = False ,
38+ desc = 'collect detailed content-view output from hammer' )
3739 ]
3840 pumactl = 'pumactl %s -S /usr/share/foreman/tmp/puma.state'
3941
@@ -143,7 +145,25 @@ def setup(self):
143145 --sasl-mechanism=ANONYMOUS' ,
144146 suggest_filename = 'qpid-stat_-q'
145147 )
146- self .add_cmd_output ("hammer ping" , tags = "hammer_ping" , timeout = 120 )
148+ self .add_cmd_output ([
149+ 'hammer ping' ,
150+ 'hammer status' ,
151+ ], cmd_as_tag = True , subdir = 'hammer' , timeout = 120 )
152+
153+ orgs = []
154+ if (org_ret := self .collect_cmd_output (
155+ 'hammer organization list' ,
156+ subdir = 'hammer'
157+ ))['status' ] == 0 :
158+ lines = org_ret ['output' ].splitlines ()
159+ n_idx = [
160+ s .strip ().lower () for s in lines [1 ].split ('|' )
161+ ].index ('name' )
162+ for line in lines [3 :- 1 ]:
163+ orgs .append (quote (line .split ('|' )[n_idx ].strip ()))
164+
165+ for org in orgs :
166+ self ._collect_organization_hammer (org )
147167
148168 # Dynflow Sidekiq
149169 self .add_cmd_output ('systemctl list-units dynflow*' ,
@@ -184,6 +204,44 @@ def setup(self):
184204 self .collect_foreman_db ()
185205 self .collect_proxies ()
186206
207+ def _collect_organization_hammer (self , org ):
208+ """
209+ Collect hammer outputs for an organization
210+
211+ :param org: The name of the organization within Foreman/Satellite
212+ :type org: ``str``
213+ """
214+ org_dir = f"hammer/organizations/{ org } "
215+ org_opt = f"--organization { org } "
216+ self .add_cmd_output ([
217+ f"hammer organization info --name { org } " ,
218+ f"hammer subscription list { org_opt } "
219+ ], subdir = org_dir )
220+
221+ components = [
222+ 'lifecycle-environment' ,
223+ 'location'
224+ ]
225+ if self .get_option ('content-views' ):
226+ components .append ('content-view' )
227+ for com in components :
228+ com_dir = f"{ org_dir } /{ com } s"
229+ if not (entities := self .collect_cmd_output (
230+ f"hammer { com } list { org_opt } " ,
231+ subdir = com_dir
232+ ))['status' ] == 0 :
233+ continue
234+ ents = entities ['output' ].splitlines ()[1 :]
235+ name_idx = [
236+ c .strip ().lower () for c in ents [0 ].split ('|' )
237+ ].index ('name' )
238+ for ent in ents [2 :- 1 ]:
239+ ent_name = quote (ent .split ('|' )[name_idx ].strip ())
240+ self .add_cmd_output (
241+ f"hammer { com } info { org_opt } --name { ent_name } " ,
242+ subdir = com_dir
243+ )
244+
187245 def collect_foreman_db (self ):
188246 # pylint: disable=too-many-locals
189247 """ Collect foreman db and dynflow data """
0 commit comments