添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

After installing icinga2 pack from " https://github.com/StackStorm/st2contrib/tree/master/packs/icinga2 " . I not able to connect to icinga2 and seeing below error in /var/log/st2/st2sensorcontainer.log file
"Sensor "Icinga2StateChangeSensor" run method raised an exception: invalid arguments to setopt"

Also posting logs for debugging sensor container -

st2sensorcontainer --config-file=/etc/st2/st2.conf --sensor-ref=icinga2.Icinga2StateChangeSensor
2017-02-16 19:55:37,999 DEBUG [-] Using config files: /etc/st2/st2.conf
2017-02-16 19:55:38,000 DEBUG [-] Using logging config: /etc/st2/logging.sensorcontainer.conf
ERROR: Traceback (most recent call last):
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/log.py", line 185, in setup
    disable_existing_loggers=disable_existing_loggers)
  File "/usr/lib/python2.7/logging/config.py", line 85, in fileConfig
    handlers = _install_handlers(cp, formatters)
  File "/usr/lib/python2.7/logging/config.py", line 163, in _install_handlers
    h = klass(*args)
  File "/usr/lib/python2.7/logging/handlers.py", line 117, in __init__
    BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
  File "/usr/lib/python2.7/logging/handlers.py", line 64, in __init__
    logging.FileHandler.__init__(self, filename, mode, encoding, delay)
  File "/usr/lib/python2.7/logging/__init__.py", line 903, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/lib/python2.7/logging/__init__.py", line 928, in _open
    stream = open(self.baseFilename, self.mode)
IOError: [Errno 13] Permission denied: '/var/log/st2/st2sensorcontainer.log'
2017-02-16 19:55:38,002 ERROR [-] (PID:2965) SensorContainer quit due to exception.
Traceback (most recent call last):
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2reactor/cmd/sensormanager.py", line 51, in main
    _setup()
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2reactor/cmd/sensormanager.py", line 42, in _setup
    register_mq_exchanges=True, register_signal_handlers=True)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/service_setup.py", line 92, in setup
    excludes=cfg.CONF.log.excludes)
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/log.py", line 195, in setup
    raise Exception(six.text_type(exc))
Exception: [Errno 13] Permission denied: '/var/log/st2/st2sensorcontainer.log'

Please advise ..

It looks like you've tried to debug the sensor container as a user without permissions to write to the log file. You probably launched it as yourself. It will need to run as either root or st2.

That's polluting the output here with this:

Exception: [Errno 13] Permission denied: '/var/log/st2/st2sensorcontainer.log'

That's almost certainly irrelevant to your problem with setopts. Can you fix that, and then re-run the debug? Include the full error output.

Also: Have you configured the pack? (i.e. configured /opt/stackstorm/configs/icinga2.yaml?

yes I have configured the pack /opt/stackstorm/configs/icnga2.yaml.

I have fixed the above "Permission denied issue"

Please see the recent logs

(st2) root@stackstorm-reston-s2:/opt/stackstorm/packs/icinga2/sensors# st2sensorcontainer --config-file=/etc/st2/st2.conf --sensor-ref=icinga2.Icinga2StateChangeSensor
2017-02-16 20:59:52,064 DEBUG [-] Using config files: /etc/st2/st2.conf
2017-02-16 20:59:52,064 DEBUG [-] Using logging config: /etc/st2/logging.sensorcontainer.conf
2017-02-16 20:59:52,066 INFO [-] Connecting to database "st2" @ "0.0.0.0:27017" as user "None".
2017-02-16 20:59:52,165 INFO [-] Setting up container to run 1 sensors.
2017-02-16 20:59:52,165 INFO [-] 	Sensors list - [u'icinga2.Icinga2StateChangeSensor'].
2017-02-16 20:59:52,166 INFO [-] (PID:) SensorContainer started.
2017-02-16 20:59:52,167 INFO [-] Running sensor icinga2.Icinga2StateChangeSensor
2017-02-16 20:59:52,184 AUDIT [-] Access granted to "sensors_container" with the token set to expire at "2017-02-17T20:59:52.181580Z". (username='sensors_container',token_expiration='2017-02-17T20:59:52.181580Z')
2017-02-16 20:59:52,184 WARNING [-] "auth.api_url" configuration option is not configured
2017-02-16 20:59:52,203 INFO [-] Connected to amqp://guest:**@127.0.0.1:5672//
2017-02-16 20:59:52,208 INFO [-] Sensor icinga2.Icinga2StateChangeSensor started
2017-02-16 20:59:53,539 INFO [-] Found config for sensor "Icinga2StateChangeSensor"
2017-02-16 20:59:53,539 INFO [-] Watcher started
2017-02-16 20:59:53,539 INFO [-] Running sensor initialization code
2017-02-16 20:59:53,539 INFO [-] Icinga2StateChangeSensor initialized with URL: https://<icinga2 url>:5665/v1/events?queue=state_change&types=StateChange User: root Password: *****
2017-02-16 20:59:53,540 INFO [-] Running sensor in passive mode
2017-02-16 20:59:53,540 INFO [-] Setting up API connection params.
2017-02-16 20:59:53,540 WARNING [-] Sensor "Icinga2StateChangeSensor" run method raised an exception: invalid arguments to setopt.
Traceback (most recent call last):
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2reactor/container/sensor_wrapper.py", line 206, in run
    self._sensor_instance.run()
  File "/opt/stackstorm/packs/icinga2/sensors/icinga2_state_change_events.py", line 34, in run
    self.client.setup_connection()
  File "/opt/stackstorm/packs/icinga2/sensors/lib/client.py", line 47, in setup_connection
    self.conn.setopt(pycurl.USERPWD, "%s:%s" % (self.api_user, self.api_password))
TypeError: invalid arguments to setopt
2017-02-16 20:59:53,541 ERROR [-] Traceback (most recent call last):
2017-02-16 20:59:53,542 ERROR [-]   File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2reactor/container/sensor_wrapper.py", line 335, in <module>
2017-02-16 20:59:53,542 ERROR [-]     
2017-02-16 20:59:53,542 ERROR [-] obj.run()
2017-02-16 20:59:53,542 ERROR [-]   File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2reactor/container/sensor_wrapper.py", line 212, in run
2017-02-16 20:59:53,543 ERROR [-]     
2017-02-16 20:59:53,543 ERROR [-] raise Exception(msg)
2017-02-16 20:59:53,543 ERROR [-] Exception
2017-02-16 20:59:53,543 ERROR [-] : 
2017-02-16 20:59:53,543 ERROR [-]  Sensor "Icinga2StateChangeSensor" run method raised an exception: invalid arguments to setopt.
  • This line should print out the URL, the user and the password:
  • 2017-02-16 20:59:53,539 INFO [-] Icinga2StateChangeSensor initialized with URL: https://:5665/v1/events?queue=state_change&types=StateChange User: root Password: *****
    

    It looks like you've masked the password - which is great. Did you also remove the hostname from that line? I would have expected something like https://icingaserver.com:5665/v1/events?...
    If not, check the api_url value in your icinga2.yaml file.

    You referred to editing the /opt/stackstorm/configs/icnga2.yaml file - I think that's just a typo here, it should be icinga2.yaml, correct?

    The actual line that's a problem is this one:

    self.conn.setopt(pycurl.USERPWD, "%s:%s" % (self.api_user, self.api_password))
    

    I'm wondering if there's something to do with the encoding of api_password. Can you do a test like this:

    st2@st2:~$ source /opt/stackstorm/virtualenvs/icinga2/bin/activate
    (icinga2) vagrant@bwcvagrant:~$ python
    Python 2.7.6 (default, Oct 26 2016, 20:30:19)
    [GCC 4.8.4] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import pycurl
    >>> api_user= 'root'
    >>> api_password = 'password'
    >>> conn=pycurl.Curl()
    >>> conn.setopt(pycurl.USERPWD, "%s:%s" % (api_user, api_password))
    

    Try the above exactly as it is there, then try it with your root password. You can see how it succeeds with my test. Do you have any special characters that might cause issues there? e.g. unicode values?

    Hello LindsayHill,

    yes filename icnga2.yaml is typo and I have removed hostname,user name password for security reasons.
    I have tried executing above code snippet on my setup which gives 'None' output.
    I am looking at the history while installing this particular icinga2 pack it originally bailed out during installing dependencies.

    This dependencies issue has been resolved by installing these two packages:

    sudo apt-get install libcurl4-openssl-dev
    sudo apt-get install python-pycurl
    

    Please see its related logs/error:

    st2 pack install icinga2
    	[ succeeded ] download pack
    	[ succeeded ] make a prerun
    	[  failed   ] install pack dependencies
    id: 58a36a2b88cc092b25037da7
    action.ref: packs.install
    parameters: 
      packs:
      - icinga2
    status: failed
    error: st2.actions.python.SetupVirtualEnvironmentAction: DEBUG    Setting up virtualenv for pack "icinga2"
    st2.actions.python.SetupVirtualEnvironmentAction: INFO     Virtualenv path "/opt/stackstorm/virtualenvs/icinga2" doesn't exist
    st2.actions.python.SetupVirtualEnvironmentAction: DEBUG    Creating virtualenv for pack "icinga2" in "/opt/stackstorm/virtualenvs/icinga2"
    st2.actions.python.SetupVirtualEnvironmentAction: DEBUG    Creating virtualenv in "/opt/stackstorm/virtualenvs/icinga2" using Python binary "/opt/stackstorm/st2/bin/python"
    st2.actions.python.SetupVirtualEnvironmentAction: DEBUG    Running command "/opt/stackstorm/st2/bin/virtualenv -p /opt/stackstorm/st2/bin/python --always-copy /opt/stackstorm/virtualenvs/icinga2" to create virtualenv.
    st2.actions.python.SetupVirtualEnvironmentAction: DEBUG    Installing base requirements
    st2.actions.python.SetupVirtualEnvironmentAction: DEBUG    Installing pack specific requirements from "/opt/stackstorm/packs/icinga2/requirements.txt"
    Traceback (most recent call last):
      File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/runners/python_action_wrapper.py", line 242, in <module>
        obj.run()
      File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2common/runners/python_action_wrapper.py", line 154, in run
        output = action.run(**self._parameters)
      File "/opt/stackstorm/packs/packs/actions/pack_mgmt/setup_virtualenv.py", line 48, in run
        setup_pack_virtualenv(pack_name=pack_name, update=update, logger=self.logger)
      File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/util/virtualenvs.py", line 96, in setup_pack_virtualenv
        requirements_file_path=requirements_file_path)
      File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/util/virtualenvs.py", line 170, in install_requirements
        (requirements_file_path, stdout, stderr))
    Exception: Failed to install requirements from "/opt/stackstorm/packs/icinga2/requirements.txt": Collecting pycurl==7.19.0 (from -r /opt/stackstorm/packs/icinga2/requirements.txt (line 2))
      Downloading pycurl-7.19.0.tar.gz (70kB)
        Complete output from command python setup.py egg_info:
        sh: 1: curl-config: not found
        Traceback (most recent call last):
          File "<string>", line 1, in <module>
          File "/tmp/pip-build-Y6Qxsd/pycurl/setup.py", line 90, in <module>
            raise Exception, ("`%s' not found -- please install the libcurl development files" % CURL_CONFIG)
        Exception: `curl-config' not found -- please install the libcurl development files
        ----------------------------------------
     (stderr: /opt/stackstorm/virtualenvs/icinga2/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
      SNIMissingWarning
    /opt/stackstorm/virtualenvs/icinga2/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
      InsecurePlatformWarning
    Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-Y6Qxsd/pycurl/
    traceback: None
    failed_on: install pack dependencies
    start_timestamp: 2017-02-14T20:35:55.704009Z
    end_timestamp: 2017-02-14T20:36:14.937669Z
    +--------------------------+------------------------+---------------------------+-------------------------+-------------------------------+
    | id                       | status                 | task                      | action                  | start_timestamp               |
    +--------------------------+------------------------+---------------------------+-------------------------+-------------------------------+
    | 58a36a2c88cc0927859ca649 | succeeded (3s elapsed) | download pack             | packs.download          | Tue, 14 Feb 2017 20:35:56 UTC |
    | 58a36a3088cc0927859ca64b | succeeded (1s elapsed) | make a prerun             | packs.virtualenv_prerun | Tue, 14 Feb 2017 20:36:00 UTC |
    | 58a36a3288cc0927859ca64d | failed (12s elapsed)   | install pack dependencies | packs.setup_virtualenv  | Tue, 14 Feb 2017 20:36:02 UTC |
    +--------------------------+------------------------+---------------------------+-------------------------
    

    However I have installed icinga2 pack "https://github.com/emptywee/icinga2-stackstorm.git" before on SS version 1.4 which was working fine.

    Is something got change on newer Stackstorm version for this pack?

    I have tried executing above code snippet on my setup which gives 'None' output.

    I'm not sure how you got 'None' output - when I ran it I had the output shown above - i.e. no failures or errors, no output displayed. Not 'None'.

    Can you provide (A) the OS you're using and (B) the complete output from when you tried that code snippet, with both a simple password, and your actual password? (Mask out the password for here of course).

    However I have installed icinga2 pack "https://github.com/emptywee/icinga2-stackstorm.git" before on SS version 1.4 which was working fine.
    Is something got change on newer Stackstorm version for this pack?

    From a casual look through the commit history, the requirement for pycurl has always been there, so you would always have needed to install those additional development libraries. Is your ST2 2.1 system running on the same base system as your older 1.4 system? And what version of the pack were you previously running? There may have been other changes in the history for that other repo - I haven't looked at the other repo you had used previously.

    The error message you're getting is coming from the underlying Python code - it's not an ST2 error. You should be able to debug this without ST2 involvement, which is why I suggested running the code snippet.

    Have you now fixed the problem with the missing development libraries, and updated the pack, to ensure that the dependencies are installed?

    Please see the answers below -
    (A)Can you provide the OS you're using :

    (icinga2) ubuntu@stackstorm-test:~$ lsb_release -a
    No LSB modules are available.
    Distributor ID:	Ubuntu
    Description:	Ubuntu 14.04.4 LTS
    Release:	14.04
    Codename:	trusty
    

    (B)The result below gives no error/failure but no output displayed that's why it was showing 'None'

    Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
    [GCC 4.8.4] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import pycurl
    >>> api_user= 'root'
    >>> api_password = '*****'
    >>> conn=pycurl.Curl()
    >>> conn.setopt(pycurl.USERPWD, "%s:%s" % (api_user, api_password))
    >>> print conn
    <pycurl.Curl object at 0x165fcd0>
    >>> print conn.setopt(pycurl.USERPWD, "%s:%s" % (api_user, api_password))
    

    -->Is your ST2 2.1 system running on the same base system as your older 1.4 system?

    -->what version of the pack were you previously running?
    name: icinga2
    description: Icinga2 Integration pack
    version: 0.2.0

    yes,I have fixed the problem with the missing development libraries by installing pycurl/libcurl and ran command st2 run packs.setup_virtualenv packs=icinga2 to successfully install this pack and registered it.

    OK, sorry it's taken so long, but I've been able to reproduce it, and I've got a workaround.

    The problem is related to unicode handling. There have been improvements to ST2 over the last ~6 months to improve unicode handling - e.g. StackStorm/st2#3116

    It looks like those config parameters are read as Unicode objects. But see this: http://pycurl.io/docs/latest/unicode.html#legacy-pycurl-versions

    Prior to PycURL 7.19.3 Unicode data was not accepted at all:

    This pack has pycurl fixed to 7.19.0.

    As a quick workaround, we can force encoding on those parameters to utf-8. See this PR: StackStorm-Exchange/stackstorm-icinga2#1

    Prior to that change getting merged (or someone suggesting a proper fix), you can make the same change to your own client.py file.