Hello one and all, and of course I am new to Prefe...
# ask-community
f
Hello one and all, and of course I am new to Prefect so please forgive the following code snippet - I am attempting to connect to a webhook for notifications purposes in Teams, what I have is working, however, I also need the project name as well as the a link to a failed Flow's logs (e.g. http://172.18.1.5:8080/default/flow-run/618e28e6-e0ac-44aa-85e3-ccf4f865c833?logs=). This is what I have so far:
import requests
import os
def vent(flow:str,state:str):
        
msg = "Flow {0} finished in fail state '{1}'".format(flow, state)
        
g = os.environ.get("TEAMS_NOTIFICATION")# webhook link to Outlook for Teams
        
<http://requests.post|requests.post>(g, json={"text": msg})
check = lambda flow,state:vent(flow.name,state.message)
.
.
.
with Flow(flow_name, schedule=None,on_failure=check) as flow:
Which is probably not optimal but I just found the API and I don't have the time to tuck in at the moment. Any help is greatly appreciated. Thanks.
d
Hi @Frederick Thomas! You can grab some of that additional information from Prefect’s context
You can also construct a url from the Flow Run ID:
<https://cloud.prefect.io/prefect/flow-run/{YOUR_FLOW_RUN_ID}>
f
@Dylan Thanks so very much!! Sorry that I didn't answer right away, I have a lot of work to do... I will post what I have so far but I still cannot locate project name, so again any help will...
def vent(flow,state):
        
msg = f"More Testing - Flow {flow.name} finished in fail state '{state.message}' for more information refer to : <http://172.18.1.5:8080/default/flow-run/{context.context.flow_run_id}?logs=>"
        
<http://requests.post|requests.post>(url=prefect.config.p.teams_notification, json={"text": msg})
check = lambda flow,state:vent(flow,state)
Once again, thanks.
d
What version of Prefect are you using?
f
# prefect version
0.12.6
d
I believe we added Project information to context in a later version
f
Well my boss is having me upgrade... 😁. He'll just have to wait. Is this available in the current production version.
d
Ah, actaully
It’s not available directly in context
There’s an open issue to add it
However, you can query the Prefect Cloud/Server API for more information about the Flow and then add that to your message
Copy code
query {
  flow_by_pk(id: "your_flow_id") { 
      id
      name
      version
      project {
        id
        name
      }
    }
}