Asterisk Event Device Registration - python

I am trying to retrieve an event when a device registers an application using ARI. This can be assumed by changing the endpoint state from offline to online. The implementation that I have done in python is:
self.client.on_event ('DeviceStateChanged', self.deviceRegistration)
self.client.on_event ('PeerStatusChange', self.deviceRegistration)
self.client.on_event ('EndpointStateChange', self.deviceRegistration)
self.client.on_event ('ContactStatusChange', self.deviceRegistration)
and nothing works. Anybody can help ?

I have managed to find a way to solve it. The change of device state has listen by event EndpointStateChange. But before, we must subscribe our application to the stasis. Here the implementation :
self.client = ari.connect(.....)
self.client.applications.subscribe(applicationName="(our stasis name)",eventSource="endpoint:PJSIP")
self.client.on_endpoint_event('EndpointStateChange',self.handleDeviceRegister)
where the handleDeviceRegister method are:
def handleDeviceRegister(self, channel_obj,ev):
if channel_obj.json["state"]=="online":
print "channel change from off to online"
if anybody get another way please tell me. thanks

Related

Python canopen send a domain

I'm using the canopen python library, see https://canopen.readthedocs.io/en/latest/index.html.
I'm trying to send a domain to my CANopen node:
# nodeHeadPort.sdo['Config Data2'].phys = b'\x11\x22\x33\x44\x55'
nodeHeadPort.sdo.download(0x6006, 0, b'\x11\x22\x33\x44\x55')
But the python gives an exception with:
canopen.sdo.exceptions.SdoAbortedError: Code 0x06090011, Subindex does not exist
And in the eds file I have the following:
[6006]
ParameterName=Config Data2
ObjectType=0x7
;StorageLocation=RAM
DataType=0x000F
AccessType=rw
DefaultValue=
PDOMapping=0
I guess my call in the python program should be different (without any subindex)? Does somebody know how to do?
This is what's going on the bus:
The reason for the issue was in the CANopen slave. I have to add their support for data type domain.
https://github.com/CANopenNode/CANopenDemo/blob/master/demo/domainDemo.c

Getting connected/disconnected status from Chromecast Audio using PyChromecast

I'm trying to write a script to sense whether either of my two CC audios are disconnected, and if so, do some other stuff. I have tried a few different approaches, such as pinging the devices. The problem is, I can ping them even when I am unable to connect to them through Google Home.
So, I am trying to use PyChromecast. I've tried a few different functions within PyChromecast. The simplest one should be the one I have quoted below. However, I always get None, whether it's connected or not.
def chromcastTest():
castGarage = pychromecast.Chromecast("192.xxx.x.xx")
print(castGarage.status)
Output:
None
Try to get the chromecasts in the area with:
chromecasts = pychromecast.get_chromecasts()
You can check it in SocketClient object:
def chromcastTest():
castGarage = pychromecast.Chromecast("192.xxx.x.xx")
print(castGarage.socket_client.is_connected)

Modifying HTTPS response packet on the fly with mitmproxy

I am trying to implement an mitmproxy addon script, in order to tamper with a particular https packet data - which is by the way decrypted on the fly through mitmproxy's certificate injection.
I am following this Stack Overflow answer to a rather similar question, as well as this tutorial from the mitmproxy docs, but without any success so far.
The packet I'm targeting comes from https://api.example.com/api/v1/user/info.
Now here is the whole python script I wrote so as to tamper with this packet data, based upon the aforementioned sources :
from mitmproxy import ctx
class RespModif:
def _init_(self):
self.num = 0
def response(self, flow):
ctx.log.info("RespModif triggered")
if flow.request.url == "https://api.example.com/api/v1/user/info":
ctx.log.info("RespModif triggered -- In the if statement")
self.num = self.num + 1
ctx.log.info("RespModif -- Proceeded to %d response modifications "
"of the targetted URLs" % self.num)
addons = [
RespModif()
]
Checking out the events log, I'm able to see that the first log information ("RespModif triggered") is being reported onto the log, but the two other log infos (done from inside the if statement) are never reported, which means I think that the if statement does never succeed.
Is there something wrong with my code ?
How can I get the if statement to succeed ?
PS: The target URL is definitely correct, plus I'm using it with a registered account from the client application that is being sniffed with mitmproxy.
Have you tried to use pretty_url attribute ?
Something like :
if flow.request.pretty_url == "https://api.example.com/api/v1/user/info":
....
pretty_url attribute handles full domain name whereas url only deals with corresponding ip address.
Also logging the content of pretty_url should allow to see what exact URL is going through and give more visibility as to what the code is actually doing.

Pika-RabbitMQ: how to make a completion callback with nowait==False (re. channels in Django)?

I have a problem with implementing django-channels with RabbitMQ channel layer. I'd finished RabbitMQ tutorial and ran through Vincent Zhang's example1 and few other examples without any problem, but stumbled upon the implementation of Andy Goodwin's example2 databinding example. The problem seems to be with Pika module.
At first, pika==0.10.0 raised the following exception:
pika.exceptions.ChannelClosed: (404, "NOT_FOUND - no exchange 'binding.enquirer' in vhost '/'")
After upgrading pika to 0.11.0b1 the exception changed to
ValueError: Must have completion callback with nowait=False
Tracing back to pika's source code (channel.py), it seems that the method responsible for canceling the consumer, basic_cancel, has the follwing parameters:
nowait==False
callback is None
which isn't acceptable by the program. I don't know how to solve this. Here's my code (nothing beyond Andy's example, really):
consumers.py
class Demultiplexer(WebsocketDemultiplexer):
consumers = {
"taxpayer": TaxpayerBinding.consumer,
}
groups = ["binding.enquirer"]
models.py
class Taxpayer(models.Model):
...
class TaxpayerBinding(WebsocketBinding):
model = Taxpayer
stream = "taxpayer"
fields = ["taxpayer_id", "checksum_status", "name"]
#classmethod
def group_names(cls, *args, **kwargs):
return ["binding.enquirer"]
def has_permission(self, user, action, pk):
return True
routing.py
channel_routing = [
route_class(Demultiplexer, path="^/binding/"),
The html template and javascript inside is a mess right now, so unless crucial to solving this problem, I'd rather not show it right now (I do not know js at all, so I'll probably ask someone for help or make it another question, but I don't want to mix the two topics if not related). Please let me know, if those problems are connected and I will edit this question.
P.S. I'm a newbie so I'd be glad for any comments that will allow me to better understand what is going on. The broader the answers, the better. Thanks.
See this GitHub issue: https://github.com/pika/pika/issues/925
Basically, if you set nowait=True you must set callback=None

Check Domain Availability using Boto Route53

I love using Boto API for Amazon Web Services but now I'm not capable of finding where is the error.
I'm using AWS for check domain availability and I have created a script in Python that includes the class at this link:
https://www.codatlas.com/github.com/boto/boto/develop/boto/route53/domains/layer1.py?line=67
I call the method check_domain_availability() on passing domain name:
Route53DomainsConnection.check_domain_availability('example.com',None)
but the method returns this error:
AttributeError: 'str' object has no attribute 'make_request'
I can try to pass parameters in many modes but no result.
Where am I wrong? Thanks in advance.
P.S: I use Debian wheezy and Python3.2
More on status of subdomains
I have found a method to get the status of a record just create with route53.
this is the code:
changes = ResourceRecordSets(conn, "ZONEID")
change = changes.add_change("STRING FOR ADD NEW SUBDOMAIN")
change.add_value(MY_IP)
status = changes.commit()
If print the status variable is contained the response of commit and the status:
{u'ChangeResourceRecordSetsResponse':{u'ChangeInfo': {u'Status: u'PENDING etc.....
Now i would like to be able to swhitch to another operation only if the status of subdomamin is "SYNC" but i doesn't able to access dinamically to string for check status.
I can use a while ? Can i use sleep command ? Can anyone help me over to resolve my problem ? Thanks
You don't show your code which makes it harder to debug but this line:
Route53DomainsConnection.check_domain_availability('example.com',None)
looks suspicious. It looks like you are trying to access the check_domain_availability method from the class rather than an instance of the class. I just did the following and it worked for me:
In [1]: import boto.route53.domains
In [2]: c = boto.route53.domains.connect_to_region('us-east-1')
In [3]: c.check_domain_availability('foobar.com')
Out[3]: {u'Availability': u'UNAVAILABLE'}

Categories

Resources