formatters: also get headers
This commit is contained in:
		
					parent
					
						
							
								ac7d1d9647
							
						
					
				
			
			
				commit
				
					
						4bcdb25c80
					
				
			
		
					 3 changed files with 10 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -79,9 +79,13 @@ curl -d '{"body":"new contrib from toto: [44](http://radio.localhost/map/#44)",
 | 
			
		|||
```
 | 
			
		||||
(or localhost:4785 without docker)
 | 
			
		||||
 | 
			
		||||
### Grafana
 | 
			
		||||
### For Github
 | 
			
		||||
 | 
			
		||||
Add a webhook with an URL like ending with `?formatter=grafana&key=API_KEY'
 | 
			
		||||
Add a JSON webhook with `?formatter=github`, and put the `API_KEY` as secret
 | 
			
		||||
 | 
			
		||||
### For Grafana
 | 
			
		||||
 | 
			
		||||
Add a webhook with an URL ending with `?formatter=grafana&key=API_KEY'
 | 
			
		||||
 | 
			
		||||
## Test room
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
"""Formatters for matrix webhook."""
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def grafana(data):
 | 
			
		||||
def grafana(data, headers):
 | 
			
		||||
    """Pretty-print a grafana notification."""
 | 
			
		||||
    text = ""
 | 
			
		||||
    if "title" in data:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -35,7 +35,9 @@ async def matrix_webhook(request):
 | 
			
		|||
 | 
			
		||||
    if "formatter" in request.rel_url.query:
 | 
			
		||||
        try:
 | 
			
		||||
            data = getattr(formatters, request.rel_url.query["formatter"])(data)
 | 
			
		||||
            data = getattr(formatters, request.rel_url.query["formatter"])(
 | 
			
		||||
                data, request.headers
 | 
			
		||||
            )
 | 
			
		||||
        except AttributeError:
 | 
			
		||||
            return utils.create_json_response(
 | 
			
		||||
                HTTPStatus.BAD_REQUEST, "Unknown formatter"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue