JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.0p0 Hot Tips | CONFIDENTIAL | CodeSecure Inc |
You can use a script to download web GUI files from the command line.
This task provides a batch file for downloading warning reports from a specified analysis, along with some suggestions for modifying the script to suit your needs.
For other scripting options, see:
If you do not need the warning reports and just want a list of warnings, use codesonar dump_warnings.py instead.
To get all warnings from a single analysis, you can use the /analysis/analysis_id-allwarnings.xml URL. For example, to download all warnings from the analysis with ID 5 from the hub at http://myhub:7340, use http://myhub:7340/analysis/5-allwarnings.xml.
The file requires that special user Anonymous has the following permissions for the analysis A of interest.
See Modifying the Batch File for information on modifying the file to specify credentials for a non-Anonymous user with the required permissions.
Use the cURL shipped with CodeSonar: $CSONAR/third-party/curl/inst/bin/curl, where $CSONAR is the CodeSonar installation directory. Either:
The following file will download the HTML warning reports for:
and store them under the directory specified in the third argument to the file.
@ECHO off set CALL_DIR=%CD% set HUB=%1 set ANALYSIS_ID=%2 set SAVEDIR=%3 set ANALYSIS_CSV_URL="%HUB%/analysis/%ANALYSIS_ID%.csv" set CURL_CMD=curl if not exist "%SAVEDIR%" mkdir %SAVEDIR% cd /D %SAVEDIR% rm -fr * %CURL_CMD% %ANALYSIS_CSV_URL% -o warnings.csv for /F "skip=1 tokens=*" %%L in (warnings.csv) do call :handle_csv_line "%%L" cd /D %CALL_DIR% exit /b :handle_csv_line set LINE=%1 REM obtain URL component from last column of line set LASTCOLUMN= set /A COUNTER=0 :LOOP1BEGIN set /A COUNTER+=1 for /F "tokens=%COUNTER% delims=," %%A in (%LINE%) do ( if "%%A"=="" goto :LOOP1END set LASTCOLUMN=%%A goto :LOOP1BEGIN) :LOOP1END REM use URL component to compute URL and basename set url2="%LASTCOLUMN:~0,-4%.html" set /A COUNTER=0 :LOOP2BEGIN set /A COUNTER+=1 for /F "tokens=%COUNTER% delims=/" %%A in ("%url2%") do ( if "%%A"=="" goto :LOOP2END set basename=%%A goto :LOOP2BEGIN) :LOOP2END REM download the page %CURL_CMD% %HUB%%url2% -o %basename% exit /b
This batch file works as follows.
To use this file with your hub, do the following.
| protocol | is the protocol for your hub: http or https. |
|---|---|
| host:port | is the location of your hub. |
| aid |
is the analysis
ID for the analysis whose warnings you wish to
download. You can find the analysis ID:
|
| savepath | is the path to the savedir directory you created in the first step. |
| Get more verbose output |
For more verbose curl output,
edit download_warnings.bat so that
curl is invoked with the
-v flag. For example:
set CURL_CMD=curl -v |
|---|---|
| No files downloaded |
If the HTML warning reports are not present, check the command
line output for information. If the only line of output is the
URL of the Analysis: Warnings
CSV file, this indicates that cURL did not attempt to download
any warning reports. There are three possible reasons.
|
| Downloaded files contain "Permission Denied" messages | If there are downloaded HTML files but they contain "Permission Denied" messages rather than warning reports, this indicates that Anonymous does not have ANALYSIS_WARNING_READ permission for the analysis. You will need to specify credentials for a user with the required permissions. |
You may wish to make one or more of the following modifications.
If an Analysis: Warnings URL is specified without a query string component, the default warning filter setting for the authorizing user (Anonymous, in this case) is applied. To apply a different visibility filter, the URL must include a query string that specifies a filter value.
For example, suppose we want to specify the all visibility filter.
set ANALYSIS_CSV_URL="%HUB%/analysis/%ANALYSIS_ID%.csv?filter=""all"""
Warning reports can be output in text and XML formats as well as HTML. To download the XML versions, do the following.
set url2=%LASTCOLUMN:~0,-4%.xml
Instead of specifying the analysis ID on the command line, you can change the file to read the analysis directory from the command line and then read the most recent analysis ID from the analysis directory.
set ANALYSIS_DIR=%2
set CSONAR=codesonar.exe
for /F "tokens=*" %%g in ('%CSONAR% analysis_id.py %ANALYSIS_DIR%') do (set ANALYSIS_ID=%%g)
For example: using the hub at http://[::1]:7341, download warnings for the analysis whose analysis directory is C:\myprojects\projectX.prj_files\ and save in directory c:\tmp\mywarnings.
If your hub is configured so that special user Anonymous does not have the required permissions, you will need to edit the file to submit credentials for a suitable hub user account.
We recommend using bearer authentication. Alternative mechanisms are described in the table below.
For bearer authentication, do the following.
set /p BEARER_TOKEN=<path\to\bearerfile
| path\to\bearerfile | is the path to the file containing the bearer token you want to use. |
|---|
CURL_CMD=curl -H "Authorization: Bearer %BEARER_TOKEN%"
For more information about bearer authentication in CodeSonar, see User Sessions and Anonymous Sessions: Bearer Authentication.
| Certificate |
If the hub is configured for certificate-based
authentication, you can edit the file to
specify a suitable user
certificate.
|
||||||||
|---|---|---|---|---|---|---|---|---|---|
| Hard-Coded Username/Password |
If you will be running the batch file under secure
conditions, you may be willing to specify the account username
and password
directly in the file invocation.
For example, if your hub location is http://[::1]:7340 and the hub user account has username jean and password xyz123, the first argument to the file would be http://jean:xyz123@[::1]:7340. Example: Use the hub user account with username jean and password xyz123 to authorize downloading warnings from the hub at http://[::1]:7340 for the analysis with ID 3, saving in directory c:\tmp\mywarnings:
download_warnings http://jean:xyz123@[::1]:7340 3 c:\tmp\mywarnings
Both username and password must be URL-encoded.
|
||||||||
| Username/Password: Other | See the curl man page for alternative username/password authentication mechanisms. |
See CodeSonar HTTP API: Authentication for more information on authentication strategies.
You can follow the overall structure of this file to create batch files that download other kinds of file from the hub.
In general, the process for constructing a file will be along the following lines.
You can use your system tools to arrange for the batch file to be run automatically.
Note. This page contains references to HTTP API documentation, which is served directly by the hub and cannot be accessed via a file:// URL. For active HTTP API documentation links, start a hub (if one is not already running), then open the manual from the hub.