def update_notifo_username(user,notifo_username): # Update the profile user_profile = user.get_profile() user_profile.notifo_username = notifo_username user_profile.save() # Send a subscription request to the user notifo = Notifo( user = settings.NOTIFO_CONFIG['username'], secret = settings.NOTIFO_CONFIG['secret'], ) notifo.subscribe_user(notifo_username)
def notifo_notify(user, key, ntype, host, state, service_desc, rest): title = '%s %s' % (ntype, host) msg = '%s - %s, %s' % (state, service_desc, rest) if config is not None: sechash = generate_hash(user, host, service_desc) ackurl = 'http://%s/%s' % (external_url, b64enc('/'.join([sechash, user, host, service_desc]))) else: ackurl = None nt = Notifo(user, key) nt.send_notification(msg=msg, label='nagios', title=title, uri=ackurl)
def send_notification(login, pw, to=None, msg=None, label=None, title=None, uri=None): return Notifo(login, pw).send_notification(to,msg,label,title,uri)
def send_message(login, pw, to, msg): return Notifo(login, pw).send_message(to, msg)
def subscribe_user(login, pw, user): return Notifo(login, pw).subscribe_user(user)
def test_message_with_object(self): res = Notifo(self.sender, self.sender_token).send_message( to=self.user, msg="foo test") self.assertEqual(2201, res["response_code"])
# Read the e-mail, find the Subject and From lines, # and read the first several lines of the body. body = '' try: while True: line = raw_input() if line.startswith('From: '): sender = line[6:] if line.startswith('Subject: '): subject = line[9:] if line == '': break num_lines = 0 while num_lines < config.getint('Format','lines'): line = raw_input() body += line + "\n" num_lines += 1 except EOFError: pass msg = 'Subject: %s\nFrom: %s' % (subject, sender) if body != '': msg += '\n\n' + body + '...' if subject != '' and sender != '': notifo = Notifo(config.get('Login','user'), config.get('Login','secret')) notifo.send_notification(label=config.get('Format','label'), \ title=config.get('Format','title'), msg=msg)
def test_notify_self_with_object(self): res = Notifo(self.user, self.user_token).send_notification( to=self.user, msg="foo test") self.assertEqual(2201, res["response_code"])
def test_subscribe_with_object(self): res = Notifo(self.provider, self.token).subscribe_user("test_user") self.assertEqual(res["response_code"], 2202)