lucasheld / uptime-kuma-api

A Python wrapper for the Uptime Kuma Socket.IO API
https://uptime-kuma-api.readthedocs.io
MIT License
272 stars 21 forks source link

Please provide an example of adding a notification #7

Closed openstep closed 2 years ago

openstep commented 2 years ago

Could you please provide an example? I would like to set up a notificaton as

Notification Type: SMTP
Friendly Name: Default alert
Hostname 
Port 
Username 
Password 
From Email 
To Email: 
Default enabled: True
Apply on all existing monitors: True

What we tried so far endpoint for the addmonitors

# Add a SMTP email notification
@app.route('/addnotification', methods=['POST'])
def add_smtp_notification():
      name = request.form['name']
      type = NotificationType.SMTP
      isDefault = True
      applyExisting = True
      smtpHost =  request.form['smtpHost']
      smtpPort = request.form['smtpPort']
      smtpIgnoreTLSError = True
      smtpUsername = request.form['smtpUsername']
      smtpPassword = request.form['smtpPassword']
      customSubject = request.form['subject']
      smtpFrom = request.form['smtpFrom']
      smtpTo = request.form['smtpTo']
      api = UptimeKumaApi('URL') 
      api.login()                  
      return api.add_notification(
        name=name,
        type=type,
        isDefault=isDefault,
        applyExisting=applyExisting,
        smtpHost =  smtpHost,
        smtpPort = smtpPort,
        smtpIgnoreTLSError = smtpIgnoreTLSError,
        smtpUsername = smtpUsername,
        smtpPassword = smtpPassword,
        customSubject = customSubject,
        smtpFrom = smtpFrom,
        smtpTo = smtpTo,
        smtpDkimskipFields = True
        ), api.disconnect()

curl -d "name=TestNotification2&smtpHost=URL&smtpPort=25&smtpUsername=username&smtpPassword=password&subject=TestNotification&smtpFrom=email&smtpTo=adress" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://localhost:5000/addnotification

   raise TypeError(f"missing {len(missing_arguments)} required argument: {missing_arguments_str}")
TypeError: missing 9 required argument: 'smtpSecure', 'smtpDkimDomain', 'smtpDkimKeySelector', 'smtpDkimPrivateKey', 'smtpDkimHashAlgo', 'smtpDkimheaderFieldNames', 'smtpDkimskipFields', 'smtpCC', 'smtpBCC'

Example for a getmonitor operation

# Get existing notifications
@app.route('/getnotifications', methods=['GET'])
def get_notifications():
      api = UptimeKumaApi('URL') 
      api.login()
      return api.get_notifications(), api.disconnect()
curl http://localhost:5000/getnotifications
[{"active":true,"applyExisting":true,"id":1,"isDefault":true,"name":"Test notification","smtpFrom":"noreply-i000@xxx.com","smtpHost":"xxx.com","smtpIgnoreTLSError":true,"smtpPassword":"pass","smtpPort":25,"smtpSecure":false,"smtpTo":"address@xxx.com","smtpUsername":"username","type":"smtp","userId":1}]
lucasheld commented 2 years ago

I mistakenly assumed that all notification provider arguments are always required. But of course this is not the case. I have removed this check in version 0.5.1 and will improve this later. I think your code will work now. Otherwise please send a new message.

openstep commented 2 years ago

Thanks for the prompt response, as always.