Mitto - Searching Job Configs

API

Access the API Swagger docs after logging into Mitto by navigating to: https://{mittoURL}/docs. There you’ll be able to see information about and use all available Mitto API endpoints. For more information about the Mitto API click here.

There are two API endpoints in play to get information about a Mitto job config.
In Mitto 2.9+:

And in anything pre-2.9:

The jobs/search POST endpoint (2.9+) or the GET jobs endpoint (<2.9) can be used to get the job ID given a job name, or any string matching the job notes.

With the job ID you can then use the GET endpoint jobs/{job_id}, which among other things includes the job conf.

Python SDK

The Mitto python SDK allows you to use the API above programatically. NOTE: The SDK will be updated when 2.9 is released.

The following script will search all jobs for a job conf with an input DBO matching “postgresql” and return the job ID and the job title:

import sys
import os
from mitto_sdk import Mitto
from dotenv import load_dotenv

load_dotenv()

BASE_URL = os.getenv("MITTO_BASE_URL")
API_KEY = os.getenv("MITTO_API_KEY")

JOB_TYPE = "io"
INPUT_DBO_LIKE = "postgresql"

def main():
    """show matching jobs"""
    mitto = Mitto(
        base_url=BASE_URL,
        api_key=API_KEY
    )
    jobs = mitto.get_jobs(job_type=JOB_TYPE)
    print(f"found jobs that input into {INPUT_DBO_LIKE}:")
    for job in jobs:
        job_id = job["id"]
        job_conf = mitto.get_job(job_id=job_id)
        conf = job_conf["conf"]
        if "input" in conf and "dbo" in conf["input"]:
            if INPUT_DBO_LIKE in conf["input"]["dbo"]:
                print(f"JOB ID: {job_id} - JOB TITLE: {job['title']}")

if __name__ == "__main__":
    sys.exit(main())

This will output something like:

found jobs that input into postgresql:
JOB ID: 6 - JOB TITLE: New Query Job
JOB ID: 16 - JOB TITLE: [query] test.test_upsert_query
...

Cmd Job

As of Mitto v2.9 job confs are stored in JSON format in the default directory /var/mitto/conf. Therefore creating a CMD job to search those configs is trivial using grep. Below is an example of a CMD job that searches all jobs for confs including the string “postgresql”:

{
    "cmd": "grep 'postgresql' /var/mitto/conf/* > /var/mitto/data/jobs-with-postgresql.txt",
    "cmd_env": {},
    "exec": false,
    "shell": true
}

This job will write the output of the command grep 'postgresql' /var/mitto/conf/* to a file at /var/mitto/data/jobs-with-postgresql.txt. You can see this file using the Mitto API by navigating to https://{mittoURL}/api/file/jobs-with-postgresql.txt