1

是我参考的文件

1.sample_server.yaml

type: os.nova.server
version: 1.0
properties:
  name: cirros_server
  flavor: m1.small
  image: b86fb462-c5c2-4a08-9fe4-c9f86d05763d
  networks:
    - network: external-net

2.执行以下命令行

# openstack cluster create --profile pserver --desired-capacity 2 mycluster
# openstack cluster receiver create --type webhook --cluster mycluster --action CLUSTER_SCALE_OUT --params count=2 r_01
# export ALRM_URL01='http://vip:8777/v1/webhooks/aac3433a-40de-4d7d-830c-e0035f2a4d13/trigger?V=1&count=2'
# aodh alarm create --type gnocchi_resources_threshold --aggregation-method mean --name cpu-high --metric cpu_util --threshold 70 --comparison-operator gt --granularity 300 --evaluation-periods 1 --alarm-action $ALRM_URL01 --repeat-actions False --query metadata.user_metadata.cluster_id=$MYCLUSTER_ID --resource-type instance --resource-id f7e0e8a6-51a3-422d-b631-7ddaf65b3dfb

3.登录到每个集群节点并在那里运行一些CPU燃烧工作负载,以提高CPU利用率

我在触发警报请求时将日志输出添加到 /usr/lib/python2.7/site-packages/aodh/notifier/rest.py

class RestAlarmNotifier(notifier.AlarmNotifier):
    def notify(self, action, alarm_id, alarm_name, severity, previous,
           current, reason, reason_data, headers=None):
    body = {'alarm_name': alarm_name, 'alarm_id': alarm_id,
            'severity': severity, 'previous': previous,
            'current': current, 'reason': reason,
            'reason_data': reason_data}
    headers['content-type'] = 'application/json'
    kwargs = {'data': json.dumps(body),
              'headers': headers}
    max_retries = self.conf.rest_notifier_max_retries
    session = requests.Session()
    LOG.info('#########################')
    LOG.info(session)
    LOG.info(kwargs)
    LOG.info(action.geturl())
    LOG.info('#########################')
    session.mount(action.geturl(),
                  requests.adapters.HTTPAdapter(max_retries=max_retries))
    resp = session.post(action.geturl(), **kwargs)
    LOG.info('$$$$$$$$$$$$$$$$$$$$$$$')
    LOG.info(resp.content)
    LOG.info('$$$$$$$$$$$$$$$$$$$$$$$')

/var/log/aodh/notifier.log 日志中会输出一些错误信息,如下: enter image description here

原因是添加body请求参数引起的错误,直接post请求可以成功,例如使用curl请求不带body参数

curl -g -i -X POST 'http://vip:8777/v1/webhooks/34e91386-7176-4b30-bc17-5c3503712696/trigger?V=1'

Aodh相关版本包如下:</p>

python2-aodhclient-1.1.1-1.el7.noarch
openstack-aodh-api-7.0.0-1.el7.noarch
openstack-aodh-common-7.0.0-1.el7.noarch
openstack-aodh-listener-7.0.0-1.el7.noarch
python-aodh-7.0.0-1.el7.noarch
openstack-aodh-notifier-7.0.0-1.el7.noarch
openstack-aodh-evaluator-7.0.0-1.el7.noarch
openstack-aodh-expirer-7.0.0-1.el7.noarch

谁能指出我正确的方向?谢谢。

4

1 回答 1

1

问题已解决。是我参考的文件

  1. 修改 aodh rest.py(aodh/notifier/rest.py) https://github.com/openstack/aodh/blob/master/aodh/notifier/rest.py#L79 的 headers['content-type'] 下,添加这一行: headers['openstack-api-version'] = 'clustering 1.10'

  2. 重启 adh 服务

于 2020-09-23T08:17:49.557 回答