-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_pid.py
More file actions
55 lines (42 loc) · 1.59 KB
/
process_pid.py
File metadata and controls
55 lines (42 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import List
import typer_cloup as typer
import asyncio
from utils import validate_options as v
import watcher.watch_proc as ww
import notifications.alertmanager as nal
import notifications.email as ne
import utils.process_lookup_infos as look
import utils.logger as l
app = typer.Typer()
@app.command()
def num(num: int = typer.Argument(..., help="PID number"), \
email_to: List[str] = typer.Option(None, \
help="Email address(es) to send process report"), \
notifymethod: List[str] = typer.Option(["local"], \
help="Your additionnal notify option")):
num = v.check_PID(num)
prog = look.lookup_process_from_pid(num)
if not prog:
typer.secho(f"Process PID: {num} not found !", fg=typer.colors.RED, bold=True)
raise typer.Exit(code=1)
else:
typer.secho(f"Ok. Process PID: {num}", fg=typer.colors.BLUE, bold=True)
if notifymethod:
notifymethod = v.check_notifymethods(notifymethod)
for method in notifymethod:
typer.echo(f"Your notify option {method} will be used")
if email_to:
email_to = v.check_emails(email_to)
for m in email_to:
typer.echo(f"Email address {m} will be used")
msg = look.gather_informations(prog)
asyncio.run(ww.pswaiter(prog))
processTitle, subject, body = nal.msg_content("PID", num)
if notifymethod:
nal.send_alert(notifymethod, subject, body)
if email_to:
ne.send(email_to, processTitle, body, None, None, None, None)
if __name__ == "__main__":
app()