How does Heat set alarm configuration and get alarm back from Ceilometer? - openstack

I really need your helps. Currently, I am working on Heat auto-scaling. I already learnt some documents about auto-scaling in Heat. I know that Heat uses Ceilometer API to set alarm configuration and get alarm back from Ceilometer via Webhook. These actions are shown in HOT template (OS::Heat::Ceilometer::Alarm). I tried to look at Heat code but I still cannot find where (what modules) handle alarm actions. In particularly, what module will be responsible for creating alarm url and what module will receive and handle alarm url triggered from Ceilometer.
Thanks

for creating alarm url:
you should see the method _get_ec2_signed_url
alarm url triggered:
It's a singal in heat-cfg service. you can find more code(Liberty) in
heat/api/cfn/v1/__init__.py
mapper.connect('/signal/{arn:.*}',
controller=signal_controller,
action='signal',
conditions=dict(method=['POST']))
and heat/api/cfn/v1/signal.py
def signal(self, req, arn, body=None):
con = req.context
identity = identifier.ResourceIdentifier.from_arn(arn)
try:
self.rpc_client.resource_signal(
con,
stack_identity=dict(identity.stack()),
resource_name=identity.resource_name,
details=body)
except Exception as ex:
return exception.map_remote_error(ex)
then you can follow the call chain to find what you want

Related

telegram use schedule message

I want to schedule a telegram bot message to be sent at a specific unixtime.
As from telegrams official api (https://core.telegram.org/api/scheduled-messages) that should be possible by setting the schedule_date flag.
To schedule a message, simply provide a future unixtime in the schedule_date flag of messages.sendMessage or messages.sendMedia.
However I was not able to set that flag. To be more precisely, I do not even know how to set a flag, or if I am using the correct api.
What I have tried is to use the api directly via the browser (could use curl as well) like so: https://api.telegram.org/botBOT:TOKEN/sendMessage?chat_id=ID&text=Test&schedule_date=1653503351
I also did not find any way to access this flag via https://pypi.org/project/pyTelegramBotAPI/#description https://telepot.readthedocs.io/en/latest/#send-a-message, nor https://github.com/nickoala/telepot.
I want to implement this feature in a python environment, but any working suggestion would be much appreciated.
EDIT:
I decided to save the intention to send a telegram bot message at a certain unixtime in a database. I then create an infinite loop that checks if there are any unsent messages before the current timestamp. If the loop detects such a message it sends the message and sets a flag, that that message has been sent.
And as promised, here is a fully dockerized example of that behaviour in action: https://github.com/Sokrates1989/nameTheCountDown-lightweight
It creates a bot that you can pass a name and the duration. Once the duration has passed it sends a message with the passed name. Basically a simple countdown that you can give several names, that run simltaniously. As it is a telegram chat, you can modify the way you are informed about the end of a countdown by modifying the notificaiton of that chat.
And here is the Bot in action: http://t.me/NameTheCountdownBot
We can't do this by bot API itself, and there's no schedule_date parameter in sendMessage method:
https://core.telegram.org/bots/api#sendmessage
And what you've read is for Telegram clients, not bot API consumers.
If you don't really need unixtime, you can simply create a table for scheduled messages with a text, chat_id and a publish_time column (like 22:15), and run a command every minute to look if there's a message for current time to send. Then send the message and delete the record.
Note that the python-telegram-bot library has a built-in solution for scheduling tasks: The JobQueue. This feature is based on the APScheduler library, which you can ofc also use without python-telegram-bot.
Disclaimer: I'm currently the maintainer of python-telegram-bot.
https://core.telegram.org/method/messages.sendScheduledMessages
Now you can send scheduled messages right away

How to force trigger aodh alarm action immediately?

I have an Openstack Aodh alarm and it will start the action when the memory usage is greater than 85% for one minute. Now I would like to trigger the action immediately, manually, which means force the alarm action start even though the condition doesn't reach the limits, but how?
According to the docs, I've tried to set the state of Aodh alarm to alarm, but it didn't work, it evaluated the memory usage and do nothing(cause its less than 85%), then set the state back to ok again.
Are there any ways to force trigger Aodh alarm action? I would appreciate any help.
Here are the parts of my Aodh alarm:
aggregation_method: mean
alarm_actions: [u'trust+http://192.168.0.100:8004/v1/284e047522bd4adfa3aa5109f1c7513b/stacks/corey_test/d9915fd3-5086-4d38-971b-2694c41e8099/resources/rdgw_scaleup_policy/signal']
alarm_id: e6402673-9a8e-4745-a8df-699edd6ab57a
comparison_operator: gt
enabled: True
evaluation_periods: 1
granularity: 60
metric: memory_util
ok_actions: []
repeat_actions: True
resource_type: instance
severity: low
state: ok
state_reason: Transition to ok due to 1 samples inside threshold, most recent: 11.0
threshold: 85.0
type: gnocchi_aggregation_by_resources_threshold
Update 2020/11/04
The only thing that comes into my mind is to reduce the threshold and evalution_periods temporarily (ex: threshold:1, periods:1), that will force the alarm start scaling, after the new instance is created, recover the threshold and evalution_periods values back. It works but I don't think that is the best method.
The alarm actions are AFAIU just HTTP POSTs to the URLs listed in 'alarm_actions', so you can do it yourself (provided you have access to that URL).
In your particular case it is clearly a Heat stack scaling action. You should be able to make a HTTP POST to appropriately similar URL - replace trust+https://<host>:<port> part with public Heat endpoint (openstack catalog show orchestration) and add a valid Keystone token to the request header.
Alternatively, for Heat stack scaling you can use use the openstack stack resource signal command (that does effectively the same REST call, just helps you with auth and endpoint discovery) - the stack ID and the resource name are visible in the URL, so in your case it will be openstack stack resource signal d9915fd3-5086-4d38-971b-2694c41e8099 rdgw_scaleup_policy

How to make async requests using HTTPoison?

Background
We have an app that deals with a considerable amount of requests per second. This app needs to notify an external service, by making a GET call via HTTPS to one of our servers.
Objective
The objective here is to use HTTPoison to make async GET requests. I don't really care about the response of the requests, all I care is to know if they failed or not, so I can write any possible errors into a logger.
If it succeeds I don't want to do anything.
Research
I have checked the official documentation for HTTPoison and I see that they support async requests:
https://hexdocs.pm/httpoison/readme.html#usage
However, I have 2 issues with this approach:
They use flush to show the request was completed. I can't loggin into the app and manually flush to see how the requests are going, that would be insane.
They don't show any notifications mechanism for when we get the responses or errors.
So, I have a simple question:
How do I get asynchronously notified that my request failed or succeeded?
I assume that the default HTTPoison.get is synchronous, as shown in the documentation.
This could be achieved by spawning a new process per-request. Consider something like:
notify = fn response ->
# Any handling logic - write do DB? Send a message to another process?
# Here, I'll just print the result
IO.inspect(response)
end
spawn(fn ->
resp = HTTPoison.get("http://google.com")
notify.(resp)
end) # spawn will not block, so it will attempt to execute next spawn straig away
spawn(fn ->
resp = HTTPoison.get("http://yahoo.com")
notify.(resp)
end) # This will be executed immediately after previoius `spawn`
Please take a look at the documentation of spawn/1 I've pointed out here.
Hope that helps!

Restore a 1:1 conversation in Skype Web SDK

Is it possible to restore a 1:1 conversation?
The Conversation object in the Skype SDK seems to have such functionality. You should be able to restore a conversation by passing a href to it. But when I pass a href string as parameter to createConversation it throws the following error:
Error: ResourceNotFound
at Error (native)
at Exception (http://.../SkypeSDK.js:3346:31)
at UCWA.get (http://.../SkypeSDK.js:15141:31)
at init (http://.../SkypeSDK.js:40672:50)
at new Conversation (http://.../SkypeSDK.js:41826:25)
at createConversationModel (http://.../SkypeSDK.js:41963:36)
at BaseModel.createConversation (http://.../SkypeSDK.js:42037:48)
The lines can be a little bit off. I modified the createConveration method to pass the href to Conversation.
The href string has this format:
/ucwa/oauth/v1/applications/xxxxxxxxxxxx/communication/conversations/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
We have the following situation:
One site has the normal SDK and waits for incoming calls. If you accept the call you should be redirected to a site with the SDK+CC and answer the call. Now we are stuck at how to pass the call. We also tried with it getConversation, but it doesn't return the last incoming conversation.
Once you accept a call on one endpoint you can transfer it to another endpoint. However you cannot accept a call and then re-answer it on a different endpoint. Also, answering the call starts the process of connecting media so that endpoint has effectively picked up the call.
The href of each conversation is unique per application, and in your scenario you will have one for each site. These cannot be shared between applications.

how can i monitor iccube server and data via an external tool

I'd like to put iccube under solid monitoring so that we know when a) cube load failure or b) cube last update time exceeded the expected.
is there an api i can use to integrate with standard monitoring tools?rest, command-line etc ...
thanks in advance, assaf
Regarding the schema load failure you can check the notification service (www); you can for example receive an eMail on failure. Note that you can implement (JAVA) your own transport service to receive notifications. There is no "notification" for last update time exceeded but if you could use an external LOAD command (www) for loading your schema; in that case you will know the last update time and perform whatever logic required.
Edit: XMLA commands can be sent via any tools (e.g., Bash).
Hope that helps.

Resources