Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZbxAPI_ExceptionPermissionError returns Hash-like message. #37

Open
veracosta opened this issue Nov 6, 2015 · 0 comments
Open

ZbxAPI_ExceptionPermissionError returns Hash-like message. #37

veracosta opened this issue Nov 6, 2015 · 0 comments

Comments

@veracosta
Copy link

I wrote following code which is intended to show some error messages from Zabbix.

begin
  @zabbix.raw_api('configuration.import',
    format: 'json',
    rules: {
      groups: {
        createMissing: true
        },
      applications: {
        createMissing: true,
        updateExisting: true
        },
      templates: {
        updateExisting: true,
        createMissing: true
        },
      templateScreens: {
        updateExisting: true,
        createMissing: true      
        },
      templateLinkage: {
        createMissing: true      
        },
      items: {
        updateExisting: true,
        createMissing: true      
        },
      discoveryRules: {
        updateExisting: true,
        createMissing: true      
        },
      triggers: {
        updateExisting: true,
        createMissing: true      
        },
      graphs: {
        updateExisting: true,
        createMissing: true      
        }
    },
    source: file
  )
rescue => evar
  p evar
end

When I run this code, very long message with Ruby's Hash format will be shown. Here's the beginning of the message.

#<ZbxAPI_ExceptionPermissionError: {"code"=>-32500, "message"=>"Application error.", "data"=>"Cannot import template \"Template1\", linked templates \"Template2, Template3\" do not exist.", "debug"=>...
...
...
"function"=>"execute", "class"=>"CJSONrpc", "type"=>"->", "args"=>[]}]}>

So I tried to output only the value of "message" key by running following code.

p evar["message"]

However, following exception message has appeared.

./script.rb:73:in `rescue in block in import_templates': undefined method `[]' for #<ZbxAPI_ExceptionPermissionError:0x18db438> (NoMethodError)
        from ./script.rb:30:in `block in import_templates'
        from ./script.rb:27:in `each'
        from ./script.rb:27:in `import_templates'
        from ./script.rb:79:in `<main>'
exit status 1

It seems that the error has occurred because it's not Hash.
Is it possible to get ZbxAPI_ExceptionPermissionError as a Hash object?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant