Skip to content

Commit

Permalink
Add MVP reports
Browse files Browse the repository at this point in the history
  • Loading branch information
ShimShtein committed Sep 18, 2024
1 parent 3287cd4 commit 23c7456
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 1 deletion.
35 changes: 35 additions & 0 deletions definitions/reports/inventory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# copy the file and add the .rb suffix
module Checks
module Report
class Inventory < ForemanMaintain::Report
metadata do
description 'Facts about hosts and the rest of the inventory'
end

def run
# Hosts
hosts_by_type_count = feature(:foreman_database).query("select type, count(*) from hosts group by type")

Check failure on line 11 in definitions/reports/inventory.rb

View workflow job for this annotation

GitHub Actions / rubocop / Rubocop

Layout/LineLength: Line is too long. [112/100]

# OS usage
hosts_by_os_count = feature(:foreman_database).query("select max(operatingsystems.name) as os_name, max(operatingsystems.type) as os_type, count(*) as hosts_count from hosts inner join operatingsystems on operatingsystem_id = operatingsystems.id group by operatingsystem_id")

Check failure on line 14 in definitions/reports/inventory.rb

View workflow job for this annotation

GitHub Actions / rubocop / Rubocop

Layout/LineLength: Line is too long. [283/100]

# Facts usage
facts_by_type = feature(:foreman_database).query("select fact_names.type, min(fact_values.updated_at) as min_update_time, max(fact_values.updated_at) as max_update_time, count(fact_values.id) from fact_values inner join fact_names on fact_name_id = fact_names.id group by fact_names.type")

Check failure on line 17 in definitions/reports/inventory.rb

View workflow job for this annotation

GitHub Actions / rubocop / Rubocop

Layout/LineLength: Line is too long. [297/100]

# Audits
audits = feature(:foreman_database).query("select count(*), min(created_at), max(created_at) from audits")

Check failure on line 20 in definitions/reports/inventory.rb

View workflow job for this annotation

GitHub Actions / rubocop / Rubocop

Layout/LineLength: Line is too long. [114/100]

# Parameters
parameters = feature(:foreman_database).query("select type, count(*) from parameters group by type")

Check failure on line 23 in definitions/reports/inventory.rb

View workflow job for this annotation

GitHub Actions / rubocop / Rubocop

Layout/LineLength: Line is too long. [108/100]

self.data = {
hosts_by_type_count: hosts_by_type_count,
hosts_by_os_count: hosts_by_os_count,
facts_by_type: facts_by_type,
audits: audits,
parameters: parameters,
}
end
end
end
end
55 changes: 55 additions & 0 deletions definitions/reports/platform.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# copy the file and add the .rb suffix
module Checks
module Report
class Platform < ForemanMaintain::Report
metadata do
description 'Report about platform usages'
end

def run
# General
smart_proxies_count = feature(:foreman_database).query("select count(*) from smart_proxies").first['count'].to_i
smart_proxies_creation_date = feature(:foreman_database).query("select id, created_at from smart_proxies")

#RBAC
total_users_count = feature(:foreman_database).query("select count(*) from users").first['count'].to_i
non_admin_users_count = feature(:foreman_database).query("select count(*) from users where admin = false").first['count'].to_i

custom_roles_count = feature(:foreman_database).query("select count(*) from roles where origin = null").first['count'].to_i
taxonomies_counts = feature(:foreman_database).query("select type, count(*) from taxonomies group by type")

#Settings
modified_settings = feature(:foreman_database).query("select name from settings")

#User groups
user_groups_count = feature(:foreman_database).query("select count(*) from usergroups").first['count'].to_i

#User groups
user_groups_count = feature(:foreman_database).query("select count(*) from usergroups").first['count'].to_i

#Bookmarks
bookmarks = feature(:foreman_database).query("select id, public, owner_id, owner_type from bookmarks")

#Mail notifications
users_per_mail_notification = feature(:foreman_database).query("select max(mail_notifications.name) as notification_name, count(user_mail_notifications.user_id) from user_mail_notifications inner join mail_notifications on mail_notification_id = mail_notifications.id group by mail_notification_id")

#Webhooks
#TODO

self.data = {
smart_proxies_count: proxies_count,
smart_proxies_creation_date: proxies_creation_date,
total_users_count: total_users_count,
non_admin_users_count: non_admin_users_count,
custom_roles_count: custom_roles_count,
taxonomies_counts: taxonomies_counts,
modified_settings: modified_settings,
user_groups_count: user_groups_count,
user_groups_count: user_groups_count,
bookmarks: bookmarks,
users_per_mail_notification: users_per_mail_notification,
}
end
end
end
end
30 changes: 30 additions & 0 deletions definitions/reports/provisioning.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module Checks
module Report
class Provisioning < ForemanMaintain::Report
metadata do
description 'Provisioning facts about the system'
end

def run
hosts_in_3_months = sql_count("SELECT COUNT(*) FROM hosts WHERE managed = true AND created_at >= current_date - interval '3 months'")

# Compute resources
compute_resources_by_type = feature(:foreman_database).query("select type, count(*) from compute_resources group by type")

hosts_by_compute_resources_type = feature(:foreman_database).query("select compute_resources.type, count(hosts.id) from hosts left outer join compute_resources on compute_resource_id = compute_resources.id group by compute_resources.type")
hosts_by_compute_profile = feature(:foreman_database).query("select max(compute_profiles.name), count(hosts.id) from hosts left outer join compute_profiles on compute_profile_id = compute_profiles.id group by compute_profile_id")

# Bare metal
nics_by_type_count = feature(:foreman_database).query("select type, count(*) from nics group by type")
discovery_rules_count = sql_count("select count(*) from discovery_rules")
hosts_by_managed_count = feature(:foreman_database).query("select managed, count(*) from hosts group by managed")


# Templates
non_default_templates_per_type = feature(:foreman_database).query("select type, count(*) from templates where templates.default = false group by type")

self.data = { managed_hosts_created_in_last_3_months: hosts_in_3_months }
end
end
end
end
2 changes: 1 addition & 1 deletion definitions/reports/provisioning_usage.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Checks
module Report
class Provisioning < ForemanMaintain::Report
class ProvisioningUsage < ForemanMaintain::Report
metadata do
description 'Count hosts that have been provisioned in the last 3 months.'
end
Expand Down

0 comments on commit 23c7456

Please sign in to comment.