How to get host under a host group, By Ruby script - ruby-on-rails

I am able to get the host group id by
puts zbx.hostgroups.get(:name => "Dev" )
give this o/p
{"groupid"=>"13", "name"=>"Dev", "internal"=>"0", "flags"=>"0"}
But I want to get all the nodes under this host group. Although I tried in other way like
get all host under this host group but I didnt find groupid attribute in host please refer below o/p
puts zbx.hosts.get(:host => "ip-10-10-111-11.ec2.internal")
{"maintenances"=>[], "hostid"=>"10251", "proxy_hostid"=>"10109",
"host"=>"ip-10-10-111-11.ec2.internal", "status"=>"0",
"disable_until"=>"0", "error"=>"", "available"=>"1",
"errors_from"=>"0", "lastaccess"=>"0", "ipmi_authtype"=>"0",
"ipmi_privilege"=>"2", "ipmi_username"=>"", "ipmi_password"=>"",
"ipmi_disable_until"=>"0", "ipmi_available"=>"0",
"snmp_disable_until"=>"0", "snmp_available"=>"0",
"maintenanceid"=>"0", "maintenance_status"=>"0",
"maintenance_type"=>"0", "maintenance_from"=>"0",
"ipmi_errors_from"=>"0", "snmp_errors_from"=>"0", "ipmi_error"=>"",
"snmp_error"=>"", "jmx_disable_until"=>"0", "jmx_available"=>"0",
"jmx_errors_from"=>"0", "jmx_error"=>"",
"name"=>"ip-10-10-111-11.ec2.internal", "flags"=>"0", "templateid"=>"0"}
I didnot find any relation between hosts & hostgroups.

I got it working in the below manner
host_grps = zbx.query(
:method => "host.get",
:params => {
"output" => "extend",
"groupids" => [14]
}
)
puts host_grps
Its gives host groups in list of hashmap.

A simple JSON request for method host.get with the following parameters gives me information for all hosts that belong to the specified groups:
{ "output" : "extend", "groupids": [ "4", "12" ] }
Please consult host.get API documentation for more information.

Related

Activemerchat paypal integration is giving an error Missing required parameter: ip?

I used the below code to test my sandbox credentials but am getting the error mentioned please help in resolving the issue
> require 'activemerchant'
> #gateway = ActiveMerchant::Billing::PaypalGateway.new(
:login "abc.cc#gmail.com,
password: "weret43435ersdfdg",
signature: "ertygdfcf343333#####frfterg")
> purchase = #gateway.purchase((10* 100),
:ip => '198.16.43.574',
:currency => "USD",
:payer_id => "2",
:token => "dsfddgfdgfdgfdgdf")
When i use the above code in irb am getting the following error
ArgumentError: Missing required parameter: ip
enter image description here
If you check the source code of ActiveMerchant here, it is expecting 3 params.
def purchase(money, credit_card_or_referenced_id, options = {})
requires!(options, :ip)
commit define_transaction_type(credit_card_or_referenced_id), build_sale_or_authorization_request('Sale', money, credit_card_or_referenced_id, options)
end
First one is the amount of money, second one is the credit card or reference id and the third one is a option, where it is expecting a required ip. As in your method call you are not passing any credit card reference, it's missing the ip from the option hash.

Add SAN or Local disk to already provisioned Server in Softlayer

I am new to the softlayer rest APIs. We have a requirement where user will be allowed to add a additional SAN or Local Disk to the existing provisioned server in softlayer. For that I was referring to the REST API guide Our project is build on Ruby on Rails and we are using softlayer_api gem and so I was looking at the api ruby doc. But none of these links helped me. Are there any ruby examples for adding a disk ?
Please try the following example to upgrade a Virtual Guest in order to add a disk:
require 'rubygems'
require 'softlayer_api'
# Your SoftLayer API username.
SL_API_USERNAME = 'set me'
# Your SoftLayer API key.
SL_API_KEY = 'set me'
# Set the server id that you wish to upgrade.
server_id = 17850400
# Set the new item price id to upgrade the VSI
price_id = 51733 # 10 GB (SAN) "categoryCode": "guest_disk1", "name": "Second Disk"
# Order Template with all new item configurations
object_template = {'packageId'=> 0,
'prices'=> [
{
'id'=> price_id
}
],
'virtualGuests'=> [
{
'id'=> server_id
}
],
'properties'=> [
{
'name'=> 'NOTE_GENERAL',
'value'=> 'Adding a SAN disk'
},
{
'name'=> 'MAINTENANCE_WINDOW',
'value'=> 'now'
}
],
'complexType'=> 'SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade'
}
softlayer_client = SoftLayer::Client.new(:username => SL_API_USERNAME,
:api_key => SL_API_KEY)
product_order_service = softlayer_client.service_named('SoftLayer_Product_Order')
begin
result = product_order_service.verifyOrder(object_template)
puts 'Result: '
puts result.inspect
rescue Exception => e
puts 'Unable to add the new SAN Disk ...'
$stdout.print(e.inspect)
end
Note: Once your script is ready, please change from verifyOrder to placeOrder.
To get valid prices for upgrade, please review:
SoftLayer_Virtual_Guest::getUpgradeItemPrices
References:
SoftLayer_Product_Order
SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade
upgrade_examples

Gandi API : Create domain error on test environment

I'm actually working on the test environment of Gandi.
I'm using the gandi gem (https://github.com/veilleperso/gandi)
I can connect with my API key etc... but when I want to create a new domain :
domain_spec = {
'owner' => 'FLN123-GANDI',
'admin' => 'FLN123-GANDI',
'bill' => 'FLN123-GANDI',
'tech' => 'FLN123-GANDI',
'nameservers' => ['a.dns.gandi-ote.net', 'b.dns.gandi-ote.net',
'c.dns.gandi-ote.net'],
'duration' => 1
}
#api.domain.create('foo.fr', domain_spec)
I got this message :
Error on object : OBJECT_CONTACT (CAUSE_INVALID) [Your are not the owner of the domain nor a reseller]
You can only create domains in both OTE and production environment which wasn't registered.
The OTE is not an empty sandbox, it's based on the data from production environment.

JStree : create jstree from smbclient directory structure

I am using sambal gem for smbclient.
I want to create jstree from recursive directory listing from smbclient.
require "sambal"
client = Sambal::Client.new(domain:domain-name, host: host, share: 'all' ,user: 'abc', password: 'pswd')
client.cd("abc")
client.ask("recurse")
all_files_hash = client.ask("ls")
I have modified parse_files method of smbclient to have path in file listing hash.
Sample hash of direcory listing that I want to display in JStree:
all_files_hash = {"."=>{:type=>:directory}, ".."=>{:type=>:directory},
"log"=>{:type=>:directory, :path=>"\\abc"},
"softwares"=>{:type=>:directory, :path=>"\\abc"},
"test.txt"=>{:type=>:file, :path=>""},
"test_data"=>{:type=>:directory, :path=>"\\abc"},
".keep"=>{:type=>:file, :path=>"\\abc\\log"},
"alert.log"=>{:type=>:file, :path=>"\\abc\\log"},
"development.log"=>{:type=>:file, :path=>"\\abc\\log"},
"test.log"=>{:type=>:file, :path=>"\\abc\\test_data"},
"robomongo-0.8.4-x86_64.deb"=>{:type=>:file, :path=>"\\abc\\softwares"},
"sublime-text_build-3065_amd64.deb"=>{:type=>:file, :path=>"\\abc\\softwares"},
"ubuntu"=>{:type=>:directory, :path=>"\\abc\\softwares"},
"ubuntu.css"=>{:type=>:file, :path=>"\\abc\\softwares\\ubuntu"}}
How can I create jstree from recursive file listing that I have got in all_files_hash?
Expected Output :
jstree_hash = [{"text" => "abc","path" => "\\abc","children" => [{"text" => "log","path"=>"\\abc\\log","children" => [{"text" => "development.log","path"=>"\\abc\\log\\developemnt.log"},{"text" => "alert.log","path"=>"\\abc\\log\\alert.log"}]}]}}]
I followed below links but no luck :
nested hash and
iterate over deep hash
Thanks in advance..

Create a name to a EC2 instance by using AWS API

I have the following code in my app.
require 'aws-sdk'
require 'rubygems'
AWS.config({
:access_key_id => 'XXXXXXXXXXXXXXXXX',
:secret_access_key => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX',
})
ec2 = AWS::EC2.new(:ec2_endpoint => 'ec2.ap-southeast-1.amazonaws.com')
##i = ec2.instances.create(:image_id => 'ami-aabXXXXX', :instance_type => 't1.micro', :security_groups=> ['Drum-Factory'], :key_name => 'some-key' )
sleep 1 while ##i.status == :pending
......
How can i name my instance while creating it, so that it will appear in the Name column of my AWS Management Console.
Name column is actually a tag added to the instance
So you need to set the value of "Name" tag
My guess is something like this
##i.tags["Name"] = "value"
or
tag = ec2.tags.create(##i, "Name","Value")
check http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/TagCollection.html#create-instance_method
also this SO answer might be of help
For AWS, how do you set tags to a resource with the ruby aws-sdk?

Resources