Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow range as parameters in the CLI for batch operations e.g provide IDs as multiple values or ranges like 2200-2210 #55

Open
devraj opened this issue Jul 10, 2024 · 1 comment
Assignees
Labels
cli Command line interface documentation Improvements or additions to documentation enhancement New feature or request

Comments

@devraj
Copy link
Member

devraj commented Jul 10, 2024

Is your feature request related to a problem? Please describe.
The idea came to me when I was doing some support work for my own command centre where while configuring a 7000 controller I had a series of Invalid certificate alarms for the controller purely from having to reset it.

While it's absolutely legitimate that the user interface requires a user to acknowledge each alarm on its own (signifying that the user has actually looked at the alarm or event).

AttributeError: 'NoneType' object has no attribute 'href'
(gallagher-py3.11) ➜  gallagher git:(alpha-5) ✗ gala alarm process 2230
[22:16:48] Finding alarm ...                                                                                         alarms.py:219
           Processing 2230 without comment ...                                                                       alarms.py:227
Processed alarm
(gallagher-py3.11) ➜  gallagher git:(alpha-5) ✗ gala alarm process 2230
[22:16:50] Finding alarm ...                                                                                         alarms.py:219
           Processing 2230 without comment ...                                                                       alarms.py:227
Processed alarm
(gallagher-py3.11) ➜  gallagher git:(alpha-5) ✗ gala alarm list        

It occurred to me that it would be handy to batch process these events and alarms through a power tool like the cli or the tui for that matter.

Describe the solution you'd like
This solution requires no modification to the SDK per say as each event or alarm would still have to be processed one at a time i.e multiple REST calls.

The command line on the other hand would provide the options such as:

  • gala alarm process 2230 2231 -m "message"
  • gala alarm process 2200-2210 -m "message"

for the CLI to process those range of alarms of events.

I would expect the CLI tool to:

  • Present a summary message of each one of those alarms or events processed (success or failure on each one of them)
  • Possibly ask for confirmation before it proceeds to do a bulk operations with an --confirm style argument for non interactive execution

Describe alternatives you've considered
You could use --json output and then pipe this through the cli via bash?

Additional context
Standard Unix commands would provide multiple values by

  • repeating parameters grep -e pattern1 -e pattern2 file.txt
  • providing a list of values ls file1.txt file2.txt file3.txt
@devraj devraj added enhancement New feature or request cli Command line interface labels Jul 10, 2024
@devraj devraj added this to the alpha-finalisation milestone Jul 10, 2024
@devraj devraj self-assigned this Jul 10, 2024
@devraj devraj changed the title Allow range as parameters in the CLI for batch operations e.g provide IDs as 2230,2232 or 2231 2232 or ranges like 2200-2210 Allow range as parameters in the CLI for batch operations e.g provide IDs as multiple or ranges like 2200-2210 Jul 11, 2024
@devraj devraj changed the title Allow range as parameters in the CLI for batch operations e.g provide IDs as multiple or ranges like 2200-2210 Allow range as parameters in the CLI for batch operations e.g provide IDs as multiple values or ranges like 2200-2210 Jul 11, 2024
devraj added a commit that referenced this issue Jul 11, 2024
first loged while i was trying to acknowledge multiple alarms, this
adds support in the alarms cli for multiple arguments @tiangolo/typer makes
this super simple to do.

i will add a comment for reference so other endpoints know how
to do this

refs #55
@devraj
Copy link
Member Author

devraj commented Jul 11, 2024

For reference, Typer will allow you quite easily do this for arguments, to achieve the following:

gala alarm process 2299 2200 2202

you can define the signature as:

from typing import Optional, List
from typing_extensions import Annotated

import typer

app = AsyncTyper(
    help="List, query, follow, act on alarms in the command centre"
)

@app.command("ack")
async def acknowledge(
    ids: Annotated[List[int], typer.Argument(help="alarm id")], #multiple ids
    message: Annotated[
        Optional[str],
        typer.Option(
            "-m",
            "--message",
            help="comment to add to history",
        ),
    ] = None,
):
    for id in ids:
        print(id)

where

ids: Annotated[List[int], typer.Argument(help="alarm id")], #multiple ids

will always result in a list and thus you must iterate over it.

devraj added a commit that referenced this issue Jul 11, 2024
for non-interative operation of bulk updates via the api endpoints

refs #55
@devraj devraj added the documentation Improvements or additions to documentation label Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Command line interface documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant