本文整理汇总了Python中azure.servicebus.ServiceBusService.send_event方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceBusService.send_event方法的具体用法?Python ServiceBusService.send_event怎么用?Python ServiceBusService.send_event使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类azure.servicebus.ServiceBusService
的用法示例。
在下文中一共展示了ServiceBusService.send_event方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import send_event [as 别名]
def main():
parser = argparse.ArgumentParser(description='Run automated diagnostics')
parser.add_argument('-y', action='store_true', help='Skip prompts')
parser.add_argument('--anonymous', action='store_true', help='No telemetry')
parser.add_argument('--case', help='Link output with a case, for use with Azure Support')
parser.add_argument('--human', action='store_true', help='Write human-readable text to stdout')
parser.add_argument('--feedback', action='store_true', help='Provide suggestions and/or feedback')
args=parser.parse_args()
if(args.feedback):
suggestion = raw_input("Suggestion (Press return to submit): ")
sbkey = '5QcCwDvDXEcrvJrQs/upAi+amTRMXSlGNtIztknUnAA='
sbs = ServiceBusService('linuxdiagnostics-ns', shared_access_key_name='PublicProducer', shared_access_key_value=sbkey)
event = {'event': 'feedback', 'feedback': suggestion}
sbs.send_event('linuxdiagnostics',json.dumps(event))
exit()
if(args.anonymous):
if(args.case == True):
print "Cannot report case diagnostics in anonymous mode."
else:
Diagnostics(False,args.case).print_report(args.human)
else:
if(args.y):
Diagnostics(True,args.case).print_report(args.human)
else:
prompt="In order to streamline support and drive continuous improvement, this script may transmit system data to Microsoft.\n Do you consent to this? (y/n):"
consent=raw_input(prompt)
if(consent=='y' or consent=='Y'):
Diagnostics(True,args.case).print_report(args.human)
else:
print("To run without telemetry, use the --anonymous flag")
示例2: __init__
# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import send_event [as 别名]
class Diagnostics:
def __init__(self,telemetry,case):
self.sbkey = '5QcCwDvDXEcrvJrQs/upAi+amTRMXSlGNtIztknUnAA='
self.sbs = ServiceBusService('linuxdiagnostics-ns', shared_access_key_name='PublicProducer', shared_access_key_value=self.sbkey)
self.telemetry = telemetry
self.case = case
self.report = dict()
self.data = dict()
try:
self.data['fstab'] = fstab()
self.data['vmstat'] = vmstat()
self.data['diskstats'] = diskstats()
self.data['meminfo'] = meminfo()
self.data['loadavg'] = loadavg()
self.data['proc.sys.fs'] = procsysfs()
self.data['inodes_by_mount'] = inodes_by_mp()
self.data['waagent'] = waagent()
self.check_fstab_uuid()
self.check_resourcedisk_inodes()
self.success_telemetry()
except:
self.error_telemetry(str(sys.last_value))
exit()
def print_report(self,human):
if(human):
for item in map(lambda x: human_readable(self.report[x]),self.report):
print item
else:
print json.dumps(self.report)
# == Telemetry ==
def success_telemetry(self):
if(self.telemetry):
event = {'event': 'success', 'report': self.report, 'data': self.data}
if(self.case):
event['case'] = self.case
self.sbs.send_event('linuxdiagnostics',json.dumps(event))
def error_telemetry(self,e):
if(self.telemetry):
event = {'event': 'error', 'error': e, 'report': self.report, 'data':self.data}
if(self.case):
event['case'] = self.case
sbs.send_event('linuxdiagnostics',json.dumps(event))
# == Diagnostics ==
def check_fstab_uuid(self):
uuids = map (lambda r:bool(re.match('UUID',r['fs_spec'],re.I)), self.data['fstab'])
uuids = filter(lambda x: not x, uuids)
if(len(uuids) > 0):
self.report['linux.uuid']= report("fstab doesn't use UUIDs", 'red', 'best_practices', "/etc/fstab isn't using UUIDs to reference its volumes.", '')
def check_resourcedisk_inodes(self):
mountpoint = self.data['waagent']['ResourceDisk.MountPoint']
x=filter(lambda x: x['mountpoint']==mountpoint ,self.data['inodes_by_mount'])[0]
if(x['inodes_used'] > 20):
self.report['azure.resource_disk_usage'] = report('Resource Disk Usage', 'yellow', 'data_loss',"This instance appears to be using the resource disk. Data stored on this mountpoint may be lost.", '')
示例3: send_temperature
# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import send_event [as 别名]
def send_temperature(temp):
today = datetime.datetime.now()
now = str(today)
sbs = ServiceBusService(service_namespace=sb_namespace, shared_access_key_name=key_name, shared_access_key_value=key_value)
print ('sending to Event [email protected]' + now)
event_message = '{ "DeviceId": "' + device_id + '", "DeviceName": "' + device_name + '", "Temperature": "' + str(temp) + '", "TimeStamp": "' + now + '" }'
print (event_message)
sbs.send_event(hub_name, event_message)
print ('sent!')
示例4: EventHubSender
# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import send_event [as 别名]
class EventHubSender(BaseSender):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._sender = ServiceBusService(self._config.service_namespace,
shared_access_key_name=self._config.key_name,
shared_access_key_value=self._config.key_value)
def send(self, label, data):
assert isinstance(label, str), 'label must be a string'
self._sender.send_event(label, data)
示例5: on_data
# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import send_event [as 别名]
def on_data(self, data):
# Twitter returns data in JSON format - we need to decode it first
decoded = json.loads(data)
# # Also, we convert UTF-8 to ASCII ignoring all bad characters sent by users
# print '@%s: %s' % (decoded['user']['screen_name'], decoded['text'].encode('ascii', 'ignore'))
# print ''
# return True
sbs = ServiceBusService(service_namespace=config.servns, shared_access_key_name=config.key_name, shared_access_key_value=config.key_value)
searched_tweets = "{ 'source': '" + unicode(decoded['user']['screen_name']) + "' , 'text': '" + unicode(decoded['text'].encode('ascii', 'ignore')) + "' }"
print(unicode(searched_tweets))
sbs.send_event('iot', unicode(searched_tweets))
return True
示例6: __init__
# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import send_event [as 别名]
class azure_interface:
def __init__(self, name_space, key_name, key_value, proxy = None):
self.sbs = ServiceBusService(service_namespace=name_space,shared_access_key_name=key_name, shared_access_key_value=key_value)
if proxy:
self.sbs.set_proxy('proxy.iisc.ernet.in',3128)
def event_send(self, hubname ,msg):
try:
hubStatus = self.sbs.send_event(hubname, str(msg))
print "Send Status:", repr(hubStatus)
except:
print sys.exc_info()
示例7: signal
# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import send_event [as 别名]
def signal(secs):
led.write(0)
time.sleep(secs)
led.write(1)
signal(1)
#even hub config
sbs = ServiceBusService("myhubed-ns",
shared_access_key_name="SendReceiveRule",
shared_access_key_value="hGRlK8cfxw/nU0SoH/egwJbg33BiUAi
def logging():
cells = Cell.all('wlan0')
count = len(cells)
sbs.send_event('myhub', json.dumps("Count: " + str(count)))
print "Count: " + str(count)
for i in range(count):
message = "SSID: " + cells[i].ssid + ", Signal: " + str(cells[i].signal)
sbs.send_event('myhub', json.dumps(message))
print message
signal(1)
print "Done"
# Listen for incoming connections
sock.listen(5)
print "Connection opened..."
while True:
try:
# Wait for a connection
示例8: ServiceBusService
# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import send_event [as 别名]
# GrovePi + Grove Temperature Sensor
import time
import grovepi
from azure.servicebus import ServiceBusService
key_name ='RootManageSharedAccessKey' # SharedAccessKeyName from Azure Portal
key_value='' # SharedAccessKey from Azure Portal
sbs = ServiceBusService('asatestsn', shared_access_key_name=key_name, shared_access_key_value=key_value)
sbs.create_event_hub('hubcreationfromlinux')
# Connect the Grove Temperature Sensor to analog port D4
sensor_port = 4
deviceId = "device-1"
#Declare direction to the pin.
#grovepi.pinMode (Temp_sensor,"INPUT")
while True:
try:
[temp,hum] = grovepi.dht(sensor_port,0)
CurrentTime = str(time.localtime(time.time()).tm_hour) + ":" + str(time.localtime(time.time()).tm_min) + ":"+ str(time.localtime(time.time()).tm_sec)
print "Temperature : ", temp , "Humidity : ", hum, "RecordTime : ", CurrentTime
sbs.send_event('hubcreationfromlinux', '{ "DeviceId":"' + deviceId + '", "Temperature":"' + str(temp) +'", "Humidity":"' + str(hum) +'", "RecordTime":"' + str(CurrentTime) +'"}')
# sbs.send_event('hubcreationfromlinux', '{ "DeviceId":"' + deviceId + '", "Temperature":"' + temperature +'"}')
time.sleep(1.0)
except IOError:
print "Error"
示例9: ServiceBusService
# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import send_event [as 别名]
gpio.setmode(gpio.BOARD)
channel_list=[11,12,13,15,16,18,22,29,31,33]
gpio.setup(channel_list,gpio.IN)
key_name = "SendRule"
key_value = "YEsTSbHUumqNJfnAr2O6Si0h/DIlblKpvJl3HJHFhiU="
sbs = ServiceBusService("smartwatering-ns",shared_access_key_name=key_name,shared_access_key_value=key_value)
event={}
event['device_id']=1
event['value']=0
while (True):
j='0'
j=j+str(gpio.input(11))
j=j+str(gpio.input(12))
j=j+str(gpio.input(13))
j=j+str(gpio.input(15))
j=j+str(gpio.input(16))
j=j+str(gpio.input(18))
j=j+str(gpio.input(22))
j=j+str(gpio.input(29))
j=j+str(gpio.input(31))
j=j+str(gpio.input(33))
value=int(j,2)
print(value)
event['value']=value
sbs.send_event('smartwatering',json.dump(event))
示例10: read_temp_raw
# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import send_event [as 别名]
lines = read_temp_raw(dfile)
while lines[0].strip()[-3:] != 'YES':
time.sleep(0.2)
lines = read_temp_raw(dfile)
equals_pos = lines[1].find('t=')
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
temp_c = float(temp_string) / 1000.0
return temp_c
host = socket.gethostname()
while True:
try:
temp1 = read_temp(device1_file)
temp2 = read_temp(device2_file)
body = '{\"DeviceId\": \"' + host + '\" '
now = datetime.now()
body += ', \"rowid\":' + now.strftime('%Y%m%d%H%M%S')
body += ', \"Time\":\"' + now.strftime('%Y/%m/%d %H:%M:%S') + '\"'
body += ', \"Temp1\":' + str(temp1)
body += ', \"Temp2\":' + str(temp2) + '}'
print body
sbs = ServiceBusService(service_namespace=name_space,shared_access_key_name=key_name, shared_access_key_value=key_value)
hubStatus = sbs.send_event('sensordemohub',body)
print "Send Status:", repr(hubStatus)
time.sleep(5)
except Exception as e:
print "Exception - ",
repr(e)
示例11: ServiceBusService
# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import send_event [as 别名]
import time
import sys
from azure.servicebus import ServiceBusService
key_name = "MySender"
key_value = "MyKeyGoesHere"
sbs = ServiceBusService("robotdeskeventhub-ns",shared_access_key_name=key_name, shared_access_key_value=key_value)
while(True):
print('sending...')
sbs.send_event('nameofeventhub', '{ "DeviceId": "smokerpi", "Temperature": "37.0" }')
print('sent!')
time.sleep(10)
示例12: float
# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import send_event [as 别名]
arg_query = arg
elif opt == '-t':
arg_time = float(arg)
# if arg_query == '':
tweet_id = arg_tweet_id
while True:
i = 0
for status in tweepy.Cursor(api.home_timeline, since_id = tweet_id).items(max_tweets):
if i == 0:
last_tweet_id = status.id
# print(unicode(status.text))
print("tweet : " + str(status.id))
searched_tweets = "{ 'source': '" + unicode(status.user.name) + "' , 'text': '" + unicode(status.text) + "' }"
print(unicode(searched_tweets))
sbs.send_event('iot', unicode(searched_tweets))
i = i + 1
tweet_id = last_tweet_id
print('dodo' + ' id : ' + str(last_tweet_id))
sleep(arg_time)
# else:
# searched_tweets = [status._json for status in tweepy.Cursor(api.home_timeline).items(max_tweets)]
# searched_tweets = json.dumps(searched_tweets)
# sbs.send_event('iot', searched_tweets)
# for result in tweepy.Cursor(api.search, q=query).items():
# sbs.send_event('iot', result)
# sleep(1)
示例13: EventHubServiceTest
# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import send_event [as 别名]
#.........这里部分代码省略.........
hub = EventHub()
hub.authorization_rules.append(
AuthorizationRule(
claim_type='SharedAccessKey',
claim_value='None',
rights=['Manage', 'Send', 'Listen'],
key_name='Key1',
primary_key='Wli4rewPGuEsLam95nQEwGR+e8b+ynlupZQ7VfjbQnw=',
secondary_key='jS+lERPBmbBVGJ5JzIwVRtSGYoFUeunRoADNTjwU3jU=',
)
)
result = self.sbs.update_event_hub(self.event_hub_name, hub)
# Assert
self.assertIsNotNone(result)
self.assertEqual(result.name, self.event_hub_name)
self.assertEqual(len(result.authorization_rules), 1)
self.assertEqual(result.authorization_rules[0].claim_type,
hub.authorization_rules[0].claim_type)
self.assertEqual(result.authorization_rules[0].claim_value,
hub.authorization_rules[0].claim_value)
self.assertEqual(result.authorization_rules[0].key_name,
hub.authorization_rules[0].key_name)
self.assertEqual(result.authorization_rules[0].primary_key,
hub.authorization_rules[0].primary_key)
self.assertEqual(result.authorization_rules[0].secondary_key,
hub.authorization_rules[0].secondary_key)
def test_get_event_hub_with_existing_event_hub(self):
# Arrange
self._create_event_hub(self.event_hub_name)
# Act
event_hub = self.sbs.get_event_hub(self.event_hub_name)
# Assert
self.assertIsNotNone(event_hub)
self.assertEqual(event_hub.name, self.event_hub_name)
def test_get_event_hub_with_non_existing_event_hub(self):
# Arrange
# Act
with self.assertRaises(WindowsAzureError):
resp = self.sbs.get_event_hub(self.event_hub_name)
# Assert
def test_delete_event_hub_with_existing_event_hub(self):
# Arrange
self._create_event_hub(self.event_hub_name)
# Act
deleted = self.sbs.delete_event_hub(self.event_hub_name)
# Assert
self.assertTrue(deleted)
def test_delete_event_hub_with_existing_event_hub_fail_not_exist(self):
# Arrange
self._create_event_hub(self.event_hub_name)
# Act
deleted = self.sbs.delete_event_hub(self.event_hub_name, True)
# Assert
self.assertTrue(deleted)
def test_delete_event_hub_with_non_existing_event_hub(self):
# Arrange
# Act
deleted = self.sbs.delete_event_hub(self.event_hub_name)
# Assert
self.assertFalse(deleted)
def test_delete_event_hub_with_non_existing_event_hub_fail_not_exist(self):
# Arrange
# Act
with self.assertRaises(WindowsAzureError):
self.sbs.delete_event_hub(self.event_hub_name, True)
# Assert
def test_send_event(self):
# Arrange
self._create_event_hub(self.event_hub_name)
# Act
result = self.sbs.send_event(self.event_hub_name,
'hello world')
result = self.sbs.send_event(self.event_hub_name,
'wake up world')
result = self.sbs.send_event(self.event_hub_name,
'goodbye!')
# Assert
self.assertIsNone(result)
示例14: ServiceBusEventHubTest
# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import send_event [as 别名]
#.........这里部分代码省略.........
primary_key='Wli4rewPGuEsLam95nQEwGR+e8b+ynlupZQ7VfjbQnw=',
secondary_key='jS+lERPBmbBVGJ5JzIwVRtSGYoFUeunRoADNTjwU3jU=',
)
)
result = self.sbs.update_event_hub(self.event_hub_name, hub)
# Assert
self.assertIsNotNone(result)
self.assertEqual(result.name, self.event_hub_name)
self.assertEqual(len(result.authorization_rules), 1)
self.assertEqual(result.authorization_rules[0].claim_type,
hub.authorization_rules[0].claim_type)
self.assertEqual(result.authorization_rules[0].claim_value,
hub.authorization_rules[0].claim_value)
self.assertEqual(result.authorization_rules[0].key_name,
hub.authorization_rules[0].key_name)
self.assertEqual(result.authorization_rules[0].primary_key,
hub.authorization_rules[0].primary_key)
self.assertEqual(result.authorization_rules[0].secondary_key,
hub.authorization_rules[0].secondary_key)
@record
def test_get_event_hub_with_existing_event_hub(self):
# Arrange
self._create_event_hub(self.event_hub_name)
# Act
event_hub = self.sbs.get_event_hub(self.event_hub_name)
# Assert
self.assertIsNotNone(event_hub)
self.assertEqual(event_hub.name, self.event_hub_name)
@record
def test_get_event_hub_with_non_existing_event_hub(self):
# Arrange
# Act
with self.assertRaises(AzureServiceBusResourceNotFound):
resp = self.sbs.get_event_hub(self.event_hub_name)
# Assert
@record
def test_delete_event_hub_with_existing_event_hub(self):
# Arrange
self._create_event_hub(self.event_hub_name)
# Act
deleted = self.sbs.delete_event_hub(self.event_hub_name)
# Assert
self.assertTrue(deleted)
@record
def test_delete_event_hub_with_existing_event_hub_fail_not_exist(self):
# Arrange
self._create_event_hub(self.event_hub_name)
# Act
deleted = self.sbs.delete_event_hub(self.event_hub_name, True)
# Assert
self.assertTrue(deleted)
@record
def test_delete_event_hub_with_non_existing_event_hub(self):
# Arrange
# Act
deleted = self.sbs.delete_event_hub(self.event_hub_name)
# Assert
self.assertFalse(deleted)
@record
def test_delete_event_hub_with_non_existing_event_hub_fail_not_exist(self):
# Arrange
# Act
with self.assertRaises(AzureMissingResourceHttpError):
self.sbs.delete_event_hub(self.event_hub_name, True)
# Assert
@record
def test_send_event(self):
# Arrange
self._create_event_hub(self.event_hub_name)
# Act
result = self.sbs.send_event(self.event_hub_name,
'hello world')
result = self.sbs.send_event(self.event_hub_name,
'wake up world')
result = self.sbs.send_event(self.event_hub_name,
'goodbye!')
# Assert
self.assertIsNone(result)
示例15: socket
# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import send_event [as 别名]
from httplib import HTTPConnection
from azure.servicebus import ServiceBusService
MCAST_GRP = '224.0.0.251'
MCAST_PORT = 6000
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
# bind this to the master node's IP address
sock.setsockopt(SOL_IP, IP_ADD_MEMBERSHIP,
inet_aton(MCAST_GRP)+inet_aton('10.0.0.1'))
sock.bind((MCAST_GRP, MCAST_PORT))
mreq = pack("4sl", inet_aton(MCAST_GRP), INADDR_ANY)
sock.setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP, mreq)
sbs = ServiceBusService(service_namespace='knockknockknock',
shared_access_key_name='RootManageSharedAccessKey',
shared_access_key_value=environ['ACCESS_KEY]')
sbs.create_event_hub('penny')
while True:
data, srv_sock = sock.recvfrom(8192)
srv_addr, srv_srcport = srv_sock[0], srv_sock[1]
data = loads(data.replace('\0',''))
data['srv_addr'] = srv_addr
print data
sbs.send_event('penny', unicode(dumps(data)))