Simple python script that will use the ServiceNow REST API to compare a pair of tables and output the differences. There can be more than one table pair for script to go through and can be defined via config file.
The script scans the environment files and the config file, then downloads 1 record from each table and extracts the table fields.
The CSV fieles with table fields are also output in the data
directory that the script creates. In this directory,
one will find a subdirectory for each environment and a subdirectory for each table pair.
- Python 3.12 or higher
- Poetry
- duckdb
- ServiceNow REST API
- Table comparison
The config file is a JSON file with following structure:
{
"comparison_name_1": {
"first_env_name": "service_now_table_1",
"second_env_name": "service_now_table_1"
},
"comparison_name_2": {
"first_env_name": "service_now_table_2",
"second_env_name": "service_now_table_2"
},
"comparison_name_3": {
"first_env_name": "service_now_table_3",
"second_env_name": null
}
}
In the above example, when a table has been named null
, the downloading of fields as well as comparison against the other table will be skipped.
*.env files are used to describe each environments (instance) name and credentials.
- Python 3.12 or higher
- Poetry
-
The project uses
poetry
for dependency management. To install the dependencies, run:Install the dependencies:
poetry install --no-root
-
Update the configuration file
cp config/example.table_map.json config/table_map.json
Then update the
config/table_map.json
with the table pairs you want to compare across the environments. -
Update the
.env
files with the ServiceNow instance credentials.cp -r example.env .env
Then update the secrets for each env in
.env
directory.
Activate the local virtual environment:
poetry shell
To run the script, execute the following command:
python app/main.py
Check the data
directory for the output CSV files and data/out
for the comparison results.
$ cat data/out/comparison_name_1.csv
fn__prod,fn__preprod,exists_in
,phone,only in preprod
...
sys_id,sys_id,both
name,latitude,both
...
u_some_custom_field,,only in prod
MIT License
This is a one shot project, so I don't expect any contributions.