将 Sonarqube 报告导出到 Excel - 基于主要、次要和关键类别

问题描述 投票:0回答:5

有没有办法根据主要、次要和关键类别将 Sonarqube 报告导出到 Excel?

sonarqube sonarqube-scan
5个回答
7
投票

您可以使用 REST API,将数据查询为 JSON 文本,然后将该 JSON 导出到 CSV 文件。

我使用下面的命令来获取 JSON 响应:

http://xxxxx.xx.xxxx.com:9000/api/issues/search?componentRoots=test_xxx_xx&statuses=OPEN,REOPENED&pageSize=500&pageIndex=1

componentRoots
是您的声纳项目名称。

它给出了 JSON 中的所有问题,然后我将其转换为 CSV。


5
投票

唯一的方法是使用 api/issues/search 网络服务


1
投票

是的,您可以使用 SonarQube 提供的 REST API 进行查询。 API 的文档也嵌入到每个 Sonar 实例中,因为不同的版本公开不同的 API。 我们将 Python 用于类似的工作,因为响应将采用 JSON 格式,并且更易于操作。找到您喜欢的提取问题后,将它们写入 .CSV 或 excel。

Web 服务的链接将在 Sonar 实例的页脚中。

PS:扩展答案以抵消短视答案。这里提供的只是抽象的,而不是带有查询详细信息的完整答案。

社区不推荐 使用 DB:- 如果您长期使用 Sonar,并且不会经常升级 SQ,则可以选择研究表结构并了解数据的组织方式。我们也这样做了,但是随着每次升级(更多的内部查询),它变得更加混乱。由于不涉及 ES,查询成本将节省在批量数据处理上


1
投票

请尝试使用以下命令获取 JSON 格式的所有问题。那么你可以考虑使用 jason 解析器程序来解析输出。

将“XXX:XXX”替换为“sonar-project.properties.txt”文件中“sonar.projectKey”变量中定义的 Sonar Key

http://localhost:9000/api/issues/search?componentKeys=XXX:XXX

1
投票

我使用 F12 开发人员工具来创建报告。这是一步一步的解决方案:

  1. 在打开 Sonar 报告之前,按 F12 在浏览器选项卡中打开开发者工具(参考截图)。单击网络选项卡。最初它将是空的:

  2. 在同一浏览器选项卡中打开声纳报告。

  3. 现在您必须在 URL 列中选择一个请求(请参阅第 4 点中的屏幕截图)。您必须选择 URL 格式为 - https://sonar:8443/api/issues/search? 的请求。基本 URL 可能会有所不同,具体取决于您托管 Sonar 网站的服务器名称。

  4. 点击Response标签(参考截图):

    将整个 JSON 数据复制到剪贴板。先按 Ctrl + A 然后按 Ctrl + C 复制内容。

  5. 您获得的 JSON 数据格式如下:

    所有问题的数据都存在于 issues 键中。它是数组类型,因为它包含问题列表。将整个 JSON 数据粘贴到任何记事本编辑器中,并获取 issues 节点的值。 issues 节点数据示例如下所示:

    [
    {
    "key":"AYMBNpviy48WWZHdsU1Z"
    ,"rule":"OWASP:UsingComponentWithKnownVulnerability"
    ,"severity":"MAJOR"
    ,"component":"B91661CE-50F8-45CB-8F54-29CD044EF32D"
    ,"project":"B91661CE-50F8-45CB-8F54-29CD044EF32D"
    ,"flows":[]
    ,"status":"OPEN"
    ,"message":"Filename: jquery-ui-1.10.3.custom.js | Reference: CVE-2021-41184 | CVSS Score: 6.1 | Category: CWE-79 | jQuery-UI is the official jQuery user interface library. Prior to version 1.13.0, accepting the value of the `of` option of the `.position()` util from untrusted sources may execute untrusted code. The issue is fixed in jQuery UI 1.13.0. Any string value passed to the `of` option is now treated as a CSS selector. A workaround is to not accept the value of the `of` option from untrusted sources."
    ,"author":""
    ,"tags":["cve","cwe","cwe-937","owasp-a9","vulnerability"]
    ,"transitions":["confirm"]
    ,"actions":["set_tags","comment","assign"]
    ,"comments":[]
    ,"creationDate":"2022-08-18T06:35:49+0100"
    ,"updateDate":"2022-08-18T06:35:49+0100"
    ,"type":"VULNERABILITY"
    ,"branch":"sonarqubepr"
    ,"scope":"MAIN"
    ,"quickFixAvailable":false
    },
    {
    "key":"AYMBNpviy48WWZHdsU1_"
    ,"rule":"OWASP:UsingComponentWithKnownVulnerability"
    ,"severity":"MAJOR"
    ,"component":"B91661CE-50F8-45CB-8F54-29CD044EF32D"
    ,"project":"B91661CE-50F8-45CB-8F54-29CD044EF32D"
    ,"flows":[]
    ,"status":"OPEN"
    ,"message":"Filename: jquery.ui.datepicker-ml.min.js | Reference: CVE-2021-41183 | CVSS Score: 6.1 | Category: CWE-79 | jQuery-UI is the official jQuery user interface library. Prior to version 1.13.0, accepting the value of various `*Text` options of the Datepicker widget from untrusted sources may execute untrusted code. The issue is fixed in jQuery UI 1.13.0. The values passed to various `*Text` options are now always treated as pure text, not HTML. A workaround is to not accept the value of the `*Text` options from untrusted sources."
    ,"author":""
    ,"tags":["cve","cwe","cwe-937","owasp-a9","vulnerability"]
    ,"transitions":["confirm"]
    ,"actions":["set_tags","comment","assign"]
    ,"comments":[]
    ,"creationDate":"2022-08-18T06:35:49+0100"
    ,"updateDate":"2022-08-18T06:35:49+0100"
    ,"type":"VULNERABILITY"
    ,"branch":"sonarqubepr"
    ,"scope":"MAIN"
    ,"quickFixAvailable":false
    }
    ]
    
  6. 上一步得到的json数组数据是真正有用的。使用任何在线转换器将此 JSON 数组数据转换为 EXCEL 文件。我使用了以下网站 - https://www.convertcsv.com/json-to-csv.htm

如果我的报告不止一页怎么办?

Sonar 每页加载 100 条记录。要获取下一页,您必须单击底部的Show More按钮:

每次单击Show More 按钮时,都会向 Sonar 服务器发送一个新请求,该服务器将显示在F12 开发人员工具的Network 选项卡中。因此,对于所有后续页面,重复相同的步骤以每页创建一个新的 Excel 工作表。然后手动合并所有 Excel 工作表以创建单个主报告。

注意:合并 Excel 文件时,请记住每个 Excel 文件的顶部都有一个标题行。合并文件时,您必须保留第一个 Excel 工作表的标题行,而忽略其余部分。

© www.soinside.com 2019 - 2024. All rights reserved.