diff --git a/common/peewee_model.py b/common/peewee_model.py index a7b604858..75128d86f 100644 --- a/common/peewee_model.py +++ b/common/peewee_model.py @@ -6,6 +6,7 @@ from datetime import datetime from enum import Enum +from peewee import SQL from peewee import AutoField from peewee import BooleanField from peewee import CharField @@ -16,6 +17,7 @@ from peewee import Model from peewee import TextField from peewee import UUIDField +from peewee import fn from playhouse.postgres_ext import ArrayField from playhouse.postgres_ext import BinaryJSONField @@ -131,6 +133,23 @@ class OperatingSystem(BaseModel): cves_unpatched_moderate = IntegerField(null=False) cves_unpatched_low = IntegerField(null=False) + @classmethod + def display_os_format(cls): + """Expression for OS display string ('Name Major.Minor'), null handled as 'N/A'.""" + # OS Name baseline + name_base = fn.COALESCE(cls.name, SQL("'N/A'")) + # Join Name and Major SPACE + name_major = fn.CONCAT_WS(" ", name_base, cls.major) + # Join result and Minor DOT + full_os_sql_string = fn.CONCAT_WS(".", name_major, cls.minor) + + return full_os_sql_string + + @classmethod + def sort_columns(cls): + """Columns for sorting by OS, first by name then by major last by minor)""" + return [cls.name, cls.major, cls.minor] + class Meta: """operating_system table metadata""" diff --git a/database/schema/ve_db_dev_data.sql b/database/schema/ve_db_dev_data.sql index 647b26852..4707b0549 100644 --- a/database/schema/ve_db_dev_data.sql +++ b/database/schema/ve_db_dev_data.sql @@ -10,65 +10,76 @@ INSERT INTO rh_account (id, account_number, org_id) VALUES UPDATE rh_account SET cves_without_errata = True WHERE account_number = '0'; -INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_upload, advisor_checksum) VALUES -(0, '00000000-0000-0000-0000-000000000000', 'inv-0.example.com', 0, 'https://s3/1', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2'), -(1, '00000000-0000-0000-0000-000000000001', 'inv-1.example.com', 0, 'https://s3/2', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2'), -(2, '00000000-0000-0000-0000-000000000002', 'inv-2.example.com', 0, 'https://s3/3', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2'); - -INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_evaluation, last_upload, advisor_evaluated, advisor_checksum, host_type) VALUES -(3, '00000000-0000-0000-0000-000000000003', 'inv-3.example.com', 0, 'https://s3/4', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2018-09-23 12:00:00-04', '2', null), -(4, '00000000-0000-0000-0000-000000000004', 'inv-4.example.com', 0, 'https://s3/5', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2018-09-23 12:00:00-04', '2', null), -(5, '00000000-0000-0000-0000-000000000005', 'inv-5.example.com', 0, 'https://s3/6', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2018-09-23 12:00:00-04', '2', null); - -INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, first_reported, last_updated, unchanged_since, last_upload, advisor_evaluated, advisor_checksum, advisor_unchanged_since) VALUES -(6, '00000000-0000-0000-0000-000000000006', 'inv-6.example.com', 0, 'https://s3/7', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2017-12-31 08:22:33-04', '2018-10-04 14:13:12-04', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2018-09-23 12:00:00-04', '2', '2018-09-22 12:00:00-04'); - -INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_evaluation, last_upload, advisor_checksum, host_type) VALUES -(7, '00000000-0000-0000-0000-000000000007', 'inv-7.example.com', 0, 'https://s3/7', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2', null); - -INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_evaluation, last_upload, advisor_checksum) VALUES -(8, '00000000-0000-0000-0000-000000000008', 'inv-0.redhat.com', 1, 'https://s3/8', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2'), -(9, '00000000-0000-0000-0000-000000000009', 'inv-0.redhat.com', 1, 'https://s3/9', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2'), -(10, '00000000-0000-0000-0000-000000000010', 'inv-0.redhat.com', 1, 'https://s3/10', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2'), -(11, '00000000-0000-0000-0000-000000000011', 'inv-0.ibm.com', 2, 'https://s3/11', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2'); - -INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_upload, last_evaluation, when_deleted, advisor_checksum) VALUES -(12, '00000000-0000-0000-0000-000000000012', 'inv-12.example.com', 0, 'https://s3/12', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2018-09-23 12:00:00-04', '2'), -(13, '00000000-0000-0000-0000-000000000013', 'inv-13.example.com', 0, 'https://s3/13', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2018-09-23 12:00:00-04', '2'), -(14, '00000000-0000-0000-0000-000000000014', 'inv-14.example.com', 0, 'https://s3/14', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2018-09-23 12:00:00-04', '2'); - -INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_upload, last_evaluation, advisor_evaluated, culled_timestamp, stale, advisor_checksum) VALUES -(15, '00000000-0000-0000-0000-000000000015', 'inv-15.example.com', 0, 'https://s3/15', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', NULL, NULL, '2018-09-23 12:00:00-04', '2020-01-01 00:00:00-04', 'F', '2'), -(16, '00000000-0000-0000-0000-000000000016', 'inv-16.example.com', 0, 'https://s3/16', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', NULL, NULL, '2018-09-23 12:00:00-04', '2020-01-01 00:00:00-04', 'T', '2'), -(17, '00000000-0000-0000-0000-000000000017', 'inv-17.example.com', 0, 'https://s3/17', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', NULL, NULL, '2018-09-23 12:00:00-04', '2020-01-01 00:00:00-04', 'F', '2'); - -INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_upload, last_evaluation, advisor_evaluated, stale, opt_out, advisor_checksum) VALUES -(18, '00000000-0000-0000-0000-000000000018', 'inv-18.example.com', 0, 'https://s3/18', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', NULL, NULL, '2018-09-23 12:00:00-04', 'F', 'T', '2'), -(19, '00000000-0000-0000-0000-000000000019', 'inv-19.example.com', 0, 'https://s3/18', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', NULL, NULL, '2018-09-23 12:00:00-04', 'T', 'T', '0'); - -INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_evaluation, last_upload, advisor_checksum, host_type) VALUES -(20, '00000000-0000-0000-0000-000000000020', 'inv-20.example.com', 0, 'https://s3/20', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2', 'edge'); - -INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_evaluation, last_upload, advisor_evaluated, advisor_checksum, host_type) VALUES -(21, '00000000-0000-0000-0000-000000000021', 'inv-21.example.com', 0, 'https://s3/21', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2018-09-23 12:00:00-04', '2', 'edge'); - -INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_evaluation, last_upload, advisor_evaluated, advisor_checksum, host_type) VALUES -(22, '00000000-0000-0000-0000-000000000022', 'inv-22.example.com', 0, 'https://s3/22', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2', null), -(23, '00000000-0000-0000-0000-000000000023', 'inv-23.example.com', 0, 'https://s3/23', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2', null), -(24, '00000000-0000-0000-0000-000000000024', 'inv-24.example.com', 0, 'https://s3/24', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2', null); - -INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_evaluation, last_upload, advisor_evaluated, advisor_checksum, host_type) VALUES -(25, '00000000-0000-0000-0000-000000000025', 'inv-25.example.com', 0, 'https://s3/25', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2', null), -(26, '00000000-0000-0000-0000-000000000026', 'inv-26.example.com', 0, 'https://s3/26', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2', null), -(27, '00000000-0000-0000-0000-000000000027', 'inv-27.example.com', 0, 'https://s3/27', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2', null); - -INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_evaluation, last_upload, advisor_evaluated, advisor_checksum, host_type) VALUES -(28, '00000000-0000-0000-0000-000000000028', 'inv-28.example.com', 0, 'https://s3/28', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2022-03-23 12:00:00-04', '2022-03-23 12:00:00-04', '2022-03-23 12:00:00-04', '2', null), -(29, '00000000-0000-0000-0000-000000000029', 'inv-29.example.com', 0, 'https://s3/29', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2022-03-23 12:00:00-04', '2022-03-23 12:00:00-04', '2022-03-23 12:00:00-04', '2', null), -(30, '00000000-0000-0000-0000-000000000030', 'inv-30.example.com', 0, 'https://s3/30', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2022-03-23 12:00:00-04', '2022-03-23 12:00:00-04', '2022-03-23 12:00:00-04', '2', null), -(31, '00000000-0000-0000-0000-000000000031', 'inv-31.example.com', 0, 'https://s3/31', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2022-03-23 12:00:00-04', '2022-03-23 12:00:00-04', '2022-03-23 12:00:00-04', '2', null), -(32, '00000000-0000-0000-0000-000000000032', 'inv-32.example.com', 0, 'https://s3/32', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2022-03-23 12:00:00-04', '2022-03-23 12:00:00-04', '2022-03-23 12:00:00-04', '2', null); +INSERT INTO operating_system (id, name, major, minor, lifecycle_phase, usable_for_report, cves_critical, cves_important, cves_moderate, cves_low, cves_unpatched_critical, cves_unpatched_important, cves_unpatched_moderate, cves_unpatched_low) VALUES +(1, 'RHEL', 8, 1, 'minor', true, 0, 0, 0, 0, 0, 0, 0, 0), +(2, 'RHEL', 8, 2, 'minor', true, 0, 0, 0, 0, 0, 0, 0, 0), +(3, 'RHEL', 8, 3, 'minor', true, 0, 0, 0, 0, 0, 0, 0, 0), +(4, 'CentOS', 8, 1, 'minor', true, 0, 0, 0, 0, 0, 0, 0, 0), +(5, 'RHEL', 7, 3, 'minor', true, 0, 0, 0, 0, 0, 0, 0, 0), +(6, 'RHEL', 7, 4, 'minor', true, 0, 0, 0, 0, 0, 0, 0, 0), +(7, 'RHEL', 7, 8, 'minor', true, 0, 0, 0, 0, 0, 0, 0, 0), +(8, 'RHEL', 7, 9, 'minor', true, 0, 0, 0, 0, 0, 0, 0, 0) +ON CONFLICT (name, major, minor, lifecycle_phase) DO NOTHING; + +INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_upload, advisor_checksum, operating_system_id) VALUES +(0, '00000000-0000-0000-0000-000000000000', 'inv-0.example.com', 0, 'https://s3/1', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2', 1), +(1, '00000000-0000-0000-0000-000000000001', 'inv-1.example.com', 0, 'https://s3/2', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2', 1), +(2, '00000000-0000-0000-0000-000000000002', 'inv-2.example.com', 0, 'https://s3/3', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2', 2); + +INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_evaluation, last_upload, advisor_evaluated, advisor_checksum, host_type, operating_system_id) VALUES +(3, '00000000-0000-0000-0000-000000000003', 'inv-3.example.com', 0, 'https://s3/4', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2018-09-23 12:00:00-04', '2', null, 2), +(4, '00000000-0000-0000-0000-000000000004', 'inv-4.example.com', 0, 'https://s3/5', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2018-09-23 12:00:00-04', '2', null, 2), +(5, '00000000-0000-0000-0000-000000000005', 'inv-5.example.com', 0, 'https://s3/6', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2018-09-23 12:00:00-04', '2', null, 3); + +INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, first_reported, last_updated, unchanged_since, last_upload, advisor_evaluated, advisor_checksum, advisor_unchanged_since, operating_system_id) VALUES +(6, '00000000-0000-0000-0000-000000000006', 'inv-6.example.com', 0, 'https://s3/7', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2017-12-31 08:22:33-04', '2018-10-04 14:13:12-04', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2018-09-23 12:00:00-04', '2', '2018-09-22 12:00:00-04', 3); + +INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_evaluation, last_upload, advisor_checksum, host_type, operating_system_id) VALUES +(7, '00000000-0000-0000-0000-000000000007', 'inv-7.example.com', 0, 'https://s3/7', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2', null, 4); + +INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_evaluation, last_upload, advisor_checksum, operating_system_id) VALUES +(8, '00000000-0000-0000-0000-000000000008', 'inv-0.redhat.com', 1, 'https://s3/8', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2', NULL), +(9, '00000000-0000-0000-0000-000000000009', 'inv-0.redhat.com', 1, 'https://s3/9', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2', 8), +(10, '00000000-0000-0000-0000-000000000010', 'inv-0.redhat.com', 1, 'https://s3/10', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2', 8), +(11, '00000000-0000-0000-0000-000000000011', 'inv-0.ibm.com', 2, 'https://s3/11', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2', 6); + +INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_upload, last_evaluation, when_deleted, advisor_checksum, operating_system_id) VALUES +(12, '00000000-0000-0000-0000-000000000012', 'inv-12.example.com', 0, 'https://s3/12', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2018-09-23 12:00:00-04', '2', 6), +(13, '00000000-0000-0000-0000-000000000013', 'inv-13.example.com', 0, 'https://s3/13', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2018-09-23 12:00:00-04', '2', 7), +(14, '00000000-0000-0000-0000-000000000014', 'inv-14.example.com', 0, 'https://s3/14', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2018-09-23 12:00:00-04', '2', 7); + +INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_upload, last_evaluation, advisor_evaluated, culled_timestamp, stale, advisor_checksum, operating_system_id) VALUES +(15, '00000000-0000-0000-0000-000000000015', 'inv-15.example.com', 0, 'https://s3/15', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', NULL, NULL, '2018-09-23 12:00:00-04', '2020-01-01 00:00:00-04', 'F', '2', 8), +(16, '00000000-0000-0000-0000-000000000016', 'inv-16.example.com', 0, 'https://s3/16', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', NULL, NULL, '2018-09-23 12:00:00-04', '2020-01-01 00:00:00-04', 'T', '2', 1), +(17, '00000000-0000-0000-0000-000000000017', 'inv-17.example.com', 0, 'https://s3/17', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', NULL, NULL, '2018-09-23 12:00:00-04', '2020-01-01 00:00:00-04', 'F', '2', 2); + +INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_upload, last_evaluation, advisor_evaluated, stale, opt_out, advisor_checksum, operating_system_id) VALUES +(18, '00000000-0000-0000-0000-000000000018', 'inv-18.example.com', 0, 'https://s3/18', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', NULL, NULL, '2018-09-23 12:00:00-04', 'F', 'T', '2', 3), +(19, '00000000-0000-0000-0000-000000000019', 'inv-19.example.com', 0, 'https://s3/18', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', NULL, NULL, '2018-09-23 12:00:00-04', 'T', 'T', '0', NULL); + +INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_evaluation, last_upload, advisor_checksum, host_type, operating_system_id) VALUES +(20, '00000000-0000-0000-0000-000000000020', 'inv-20.example.com', 0, 'https://s3/20', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2', 'edge', 4); + +INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_evaluation, last_upload, advisor_evaluated, advisor_checksum, host_type, operating_system_id) VALUES +(21, '00000000-0000-0000-0000-000000000021', 'inv-21.example.com', 0, 'https://s3/21', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2018-09-22 12:00:00-04', '2018-09-22 12:00:00-04', '2018-09-23 12:00:00-04', '2', 'edge', 4); + +INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_evaluation, last_upload, advisor_evaluated, advisor_checksum, host_type, operating_system_id) VALUES +(22, '00000000-0000-0000-0000-000000000022', 'inv-22.example.com', 0, 'https://s3/22', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2', null, 5), +(23, '00000000-0000-0000-0000-000000000023', 'inv-23.example.com', 0, 'https://s3/23', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2', null, 5), +(24, '00000000-0000-0000-0000-000000000024', 'inv-24.example.com', 0, 'https://s3/24', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2', null, 5); + +INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_evaluation, last_upload, advisor_evaluated, advisor_checksum, host_type, operating_system_id) VALUES +(25, '00000000-0000-0000-0000-000000000025', 'inv-25.example.com', 0, 'https://s3/25', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2', null, 5), +(26, '00000000-0000-0000-0000-000000000026', 'inv-26.example.com', 0, 'https://s3/26', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2', null, 5), +(27, '00000000-0000-0000-0000-000000000027', 'inv-27.example.com', 0, 'https://s3/27', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2022-03-17 12:00:00-04', '2', null, 5); + +INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, s3_url, vmaas_json, json_checksum, last_evaluation, last_upload, advisor_evaluated, advisor_checksum, host_type, operating_system_id) VALUES +(28, '00000000-0000-0000-0000-000000000028', 'inv-28.example.com', 0, 'https://s3/28', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2022-03-23 12:00:00-04', '2022-03-23 12:00:00-04', '2022-03-23 12:00:00-04', '2', null, 5), +(29, '00000000-0000-0000-0000-000000000029', 'inv-29.example.com', 0, 'https://s3/29', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2022-03-23 12:00:00-04', '2022-03-23 12:00:00-04', '2022-03-23 12:00:00-04', '2', null, 5), +(30, '00000000-0000-0000-0000-000000000030', 'inv-30.example.com', 0, 'https://s3/30', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2022-03-23 12:00:00-04', '2022-03-23 12:00:00-04', '2022-03-23 12:00:00-04', '2', null, 5), +(31, '00000000-0000-0000-0000-000000000031', 'inv-31.example.com', 0, 'https://s3/31', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2022-03-23 12:00:00-04', '2022-03-23 12:00:00-04', '2022-03-23 12:00:00-04', '2', null, 5), +(32, '00000000-0000-0000-0000-000000000032', 'inv-32.example.com', 0, 'https://s3/32', '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ]}', '1', '2022-03-23 12:00:00-04', '2022-03-23 12:00:00-04', '2022-03-23 12:00:00-04', '2', null, 5); INSERT INTO cve_metadata (id, cve, impact_id, cvss3_score, cvss3_metrics, public_date, description, advisories_list, exploit_data, celebrity_name) VALUES (0, 'CVE-2013-1', 7, NULL, NULL, '2013-11-12 00:00:00+00', 'CVE-2013-1 desc', '[]', NULL, NULL), @@ -300,6 +311,7 @@ INSERT INTO timestamp_kv (name, value) VALUES ('last_eval_repo_based', '2018-04-05T01:23:45+02:00'); SELECT setval('system_platform_id_seq', 100); +SELECT setval('operating_system_id_seq', 8); SELECT setval('cve_metadata_id_seq', 100); SELECT setval('rh_account_id_seq', 100); SELECT setval('insights_rule_id_seq', 100); diff --git a/manager/base.py b/manager/base.py index aed2696f4..c09773d25 100644 --- a/manager/base.py +++ b/manager/base.py @@ -46,6 +46,7 @@ from common.peewee_model import CveRuleMapping from common.peewee_model import InsightsRule from common.peewee_model import InventoryHosts +from common.peewee_model import OperatingSystem from common.peewee_model import RHAccount from common.peewee_model import Status from common.peewee_model import SystemGroupSet @@ -839,6 +840,9 @@ def cyndi_join(query): if UNLEASH.is_enabled(CYNDI_REPLICATION_REPLACEMENT): query = (query.switch(SystemPlatform).join(SystemGroupSet, JOIN.LEFT_OUTER)) + query = (query.switch(SystemPlatform).join(OperatingSystem, JOIN.LEFT_OUTER, + on=(SystemPlatform.operating_system_id == OperatingSystem.id))) + query = filter_allowed_groups(query, SystemGroupSet.groups) query = filter_kessel_workspace_opt_out(query, SystemGroupSet.groups) else: diff --git a/manager/cve_handler.py b/manager/cve_handler.py index 023c8861f..23fd016a1 100644 --- a/manager/cve_handler.py +++ b/manager/cve_handler.py @@ -36,6 +36,7 @@ from common.peewee_model import CveMetadata from common.peewee_model import InsightsRule from common.peewee_model import InventoryHosts +from common.peewee_model import OperatingSystem from common.peewee_model import RHAccount from common.peewee_model import SystemCveData from common.peewee_model import SystemGroupSet @@ -202,7 +203,7 @@ def __init__(self, account_data, synopsis, list_args, parsed_args, uri, ids_only "status": SQL("status_id"), "updated": SQL("updated"), "first_reported": SQL("first_reported"), - "os": OS_INFO_SORT, + "os": ([SQL("os")] if UNLEASH.is_enabled(CYNDI_REPLICATION_REPLACEMENT) else OS_INFO_SORT), "advisory_available": SQL("advisory_available"), "remediation": SQL("remediation_type_id"), "advisories_list": SQL("advisories"), @@ -274,7 +275,7 @@ def _full_query(rh_account_id, synopsis, parsed_args, filters, remediation_filte else InventoryHosts.groups.alias("inventory_group") ), InventoryHosts.system_profile, - OS_INFO_QUERY.alias("os"), + (OperatingSystem.display_os_format() if UNLEASH.is_enabled(CYNDI_REPLICATION_REPLACEMENT) else OS_INFO_QUERY).alias("os"), RHSM_LOCK_QUERY.alias("rhsm_lock"), fn.COALESCE(SystemVulnerabilities.advisory_available, True).alias("advisory_available"), fn.COALESCE(SystemVulnerabilities.remediation_type_id, remediation.PLAYBOOK.value).alias("remediation_type_id"), @@ -347,7 +348,7 @@ def _unpatched_full_query(self, rh_account_id, synopsis, parsed_args, filters) - else InventoryHosts.groups.alias("inventory_group") ), InventoryHosts.system_profile, - OS_INFO_QUERY.alias("os"), + (OperatingSystem.display_os_format() if UNLEASH.is_enabled(CYNDI_REPLICATION_REPLACEMENT) else OS_INFO_QUERY).alias("os"), RHSM_LOCK_QUERY.alias("rhsm_lock"), Value(False).alias("advisory_available"), Value(remediation.NONE.value).alias("remediation_type_id"), diff --git a/manager/filters.py b/manager/filters.py index 025e151b7..6499da12d 100644 --- a/manager/filters.py +++ b/manager/filters.py @@ -455,15 +455,30 @@ def _filter_system_by_rhel_version(query, args, _kwargs): """ if "rhel_version" in args and args["rhel_version"]: expr = None - for version in args["rhel_version"]: - if "." in version: - major, minor = version.split(".", 1) - expr = expr | \ - ((InventoryHosts.system_profile["operating_system"]["major"] == major) & - (InventoryHosts.system_profile["operating_system"]["minor"] == minor)) - else: - expr = expr | (InventoryHosts.system_profile["operating_system"]["major"] == version) - query = query.where((InventoryHosts.system_profile["operating_system"]["name"] == "RHEL") & (expr)) + if UNLEASH.is_enabled(CYNDI_REPLICATION_REPLACEMENT): + for version in args["rhel_version"]: + try: + if "." in version: + major, minor = version.split(".", 1) + major, minor = int(major), int(minor) # Operating System is storing ints + cond = (OperatingSystem.major == major) & (OperatingSystem.minor == minor) + else: + cond = OperatingSystem.major == int(version) + except (ValueError, TypeError): + continue + expr = cond if expr is None else expr | cond + if expr is not None: + query = query.where((OperatingSystem.name == "RHEL") & (OperatingSystem.lifecycle_phase == "minor") & (expr)) + else: + for version in args["rhel_version"]: + if "." in version: + major, minor = version.split(".", 1) + expr = expr | \ + ((InventoryHosts.system_profile["operating_system"]["major"] == major) & + (InventoryHosts.system_profile["operating_system"]["minor"] == minor)) + else: + expr = expr | (InventoryHosts.system_profile["operating_system"]["major"] == version) + query = query.where((InventoryHosts.system_profile["operating_system"]["name"] == "RHEL") & (expr)) return query diff --git a/manager/system_handler.py b/manager/system_handler.py index b9ebdaf41..6d09de376 100644 --- a/manager/system_handler.py +++ b/manager/system_handler.py @@ -33,6 +33,7 @@ from common.peewee_model import CveMetadata from common.peewee_model import InsightsRule from common.peewee_model import InventoryHosts +from common.peewee_model import OperatingSystem from common.peewee_model import RHAccount from common.peewee_model import SystemCveData from common.peewee_model import SystemGroupSet @@ -501,7 +502,7 @@ def __init__(self, account_data, list_args, parsed_args, uri, ids_only=True): "display_name": SystemPlatform.display_name, "rules_evaluation": SystemPlatform.advisor_evaluated, "updated": InventoryHosts.updated, - "os": OS_INFO_SORT, + "os": (OperatingSystem.sort_columns() if UNLEASH.is_enabled(CYNDI_REPLICATION_REPLACEMENT) else OS_INFO_SORT), } default_sort_columns = {"default": ["-updated", "id"]} filterable_columns = {"display_name": SystemPlatform.display_name} @@ -526,7 +527,7 @@ def _full_query(rh_account_id): InventoryHosts.tags, InventoryHosts.updated, InventoryHosts.insights_id, - OS_INFO_QUERY.alias("os"), + (OperatingSystem.display_os_format() if UNLEASH.is_enabled(CYNDI_REPLICATION_REPLACEMENT) else OS_INFO_QUERY).alias("os"), RHSM_LOCK_QUERY.alias("rhsm_lock"), ( fn.COALESCE(SystemGroupSet.groups, "[]").alias("inventory_group") @@ -830,7 +831,7 @@ def handle_get(cls, **kwargs): InventoryHosts.tags, InventoryHosts.updated, InventoryHosts.insights_id, - OS_INFO_QUERY.alias("os"), + (OperatingSystem.display_os_format() if UNLEASH.is_enabled(CYNDI_REPLICATION_REPLACEMENT) else OS_INFO_QUERY).alias("os"), RHSM_LOCK_QUERY.alias("rhsm_lock"), ( fn.COALESCE(SystemGroupSet.groups, "[]").alias("inventory_group")