How to identify API V1 usage in Jira Align Self-Hosted using PowerShell
Summary
This article contains a PowerShell script to identify the API V1 usage in an Jira Align On-Premise deployment.
Environment
Jira Align Self-Hosted
Solution
The API V1 has the following endpoints
Endpoint | |
|---|---|
| 1 | Cities |
| 2 | CostCenters |
| 3 | EmpClass |
| 4 | Holidays |
| 5 | OrganizationStructures |
| 6 | PayPeriods |
| 7 | Regions |
| 8 | ReleaseVehicles |
| 9 | Tasks |
| 10 | TaskDetails |
| 11 | Teams |
| 12 | Timesheets |
| 13 | Users |
| 14 | ValueEngineering |
| 15 | WorkCodes |
| 16 | WorkHours |
The usage of the above endpoints can be detected in the IIS Logs using the following sample PowerShell script:
# Define the paths to the IIS logs
$paths = Get-ChildItem -Path 'C:\inetpub\logs\LogFiles\*\*' -Filter '*.log'
# Create an empty array to store the API calls
$apiCalls = @()
# Define the endpoints to look for
$endpoints = @("cities", "costcenters", "empclass", "holidays", "organizationstructures", "payperiods", "regions", "releasevehicles", "taskdetails", "teams", "timesheets", "users", "valueengineering", "workcodes", "workhours")
# Loop through each log file
foreach($path in $paths){
# Import the log file
$logData = Import-Csv -Path $path.FullName -Delimiter ' ' -Header ("date","time","s-ip","cs-method","cs-uri-stem","cs-uri-query","s-port","cs-username","c-ip","cs(User-Agent)","cs(Referer)","sc-status","sc-substatus","sc-win32-status")
# Filter the log data for API calls with a successful status code
$apiData = $logData | Where-Object { $_."cs-uri-stem" -like "/api/*" -and $_."sc-status" -lt 400 -and $_."cs(Referer)" -eq "-" }
# Loop through each API call
foreach($apiCall in $apiData){
# Extract the endpoint
$endpoint = ($apiCall."cs-uri-stem" -split '/api/')[1].ToLower()
# If the endpoint is in the list of endpoints to look for, add it to the array of API calls
if($endpoints -contains $endpoint){
$apiCalls += $endpoint
}
}
}
# Group the API calls by endpoint and count them
$apiCalls | Group-Object | Select-Object Name, Count | Sort-Object Name
To execute the above PowerShell script, follow these steps:
Save the script:
Copy the script and paste it into a text editor like Notepad. Save the file with a
.ps1extension, for exampleIISLogReport.ps1. Make sure to save it to a location that is easy to navigate to from the PowerShell command line.
- Verify the IIS Log file path on line 2 of the script. Modify if needed to ensure it is correct for the environment in which the script is being run.
Open PowerShell:
Click on the Start button, type
PowerShellinto the search bar, right-click on the Windows PowerShell app result, and select "Run as administrator".
Enable script execution:
By default, PowerShell restricts the execution of scripts for security reasons. You can change the execution policy to allow scripts to run. Type the following command and press Enter:
Set-ExecutionPolicy UnrestrictedThis command allows scripts downloaded from the internet to run if they are signed by a trusted publisher. When prompted, confirm the execution policy change by typing
Yand pressing Enter.
Run the script:
In the PowerShell window, navigate to the location where you saved the script. For example, if you saved it in the C:\Scripts folder, you would navigate there by typing
cd C:\Scriptsand pressing Enter. Then, to run the script, type.\IISLogReport.ps1and press Enter.
Result:
- API V1 calls will be grouped with counts displayed on the command line
- If no API V1 calls are detected in the logs, nothing will display on the command line