List all cache items in remote servers with Dalli - ruby

I have been recently picking up more learnings with Memcached and how Dalli plays along with the different caching strategies. I am trying to connect remotely to our memcachier on heroku with one of our production level projects. Through some tutorial, I found out how to connect remotely to remote memcachier through Dalli.
sandbox.rb:
require 'dalli'
memcachier_server = 'host_name:port'
memcachier_user = 'abc123'
memcachier_password = '1x8w3asdf82jdf'
cache = Dalli::Client.new(memcachier_server,
{
:username => memcachier_user,
:password => memcachier_password,
:failover => true,
:socket_timeout => 1.5,
:socket_failure_delay => 0.2
})
p cache.stat
I confirmed it works when i run ruby sandbox.rb and there comes the output:
I, [2015-03-17T01:45:20.703729 #42640] INFO -- : Dalli/SASL authenticating as abc123
I, [2015-03-17T01:45:21.305454 #42640] INFO -- : Dalli/SASL: abc123
{"xyz.memcacheir.com:11211"=>{"curr_items"=>"24446", "bytes"=>"110738688", "evictions"=>"2586065", "expired"=>"0", "cas_hits"=>"0", "cas_misses"=>"0", "cas_badval"=>"0", "limit_maxbytes"=>"120586239", "total_items"=>"3782835", "bytes_read"=>"1559184266", "bytes_written"=>"33808073647", "curr_connections"=>"5", "total_connections"=>"1098", "auth_cmds"=>"1098", "auth_errors"=>"0", "cmd_get"=>"19371543", "cmd_set"=>"3782835", "cmd_delete"=>"15829", "cmd_touch"=>"0", "cmd_flush"=>"0", "get_hits"=>"16476147", "get_misses"=>"2895396", "delete_hits"=>"4131", "delete_misses"=>"11698", "incr_hits"=>"0", "incr_misses"=>"0", "decr_hits"=>"0", "decr_misses"=>"0", "touch_hits"=>"0", "touch_misses"=>"0", "time"=>"1426527920"}}
I have been trying to find out how I can dig in more into the cached keys and values. To be more specific: I want to at least list out all Keys and values currently in memcached using Dalli. I can't seem to find an appropriate solution. The best match i found is this gist which helps you with getting it locally.
Any thoughts?

Related

Can't use RubyPress gem gives getaddrinfo: No such host is known. (SocketError)

I am trying to use a gem called RubyPress which allows to use Wordpress' xml-rpc api from ruby. But it always gives me this error:
getaddrinfo: No such host is known. (SocketError)
Here's my code:
require 'rubypress'
wp = Rubypress::Client.new(:host => "localhost/wordpress",
:username => "admin",
:password => "admin")
p wp.getOptions
I am able to connect fine using another gem called wp_rpc but rubypress doesn't seem to work. Rubypress seems to be maintained so i want to use it, it also seems to have more features.
Also, even when i try connecting to a real site, it gives a 403 error which is very strange.
I am running the server using XAMPP on Windows 7. How can I get it to work?
UPDATE:
Here's the code i used for posting, now it doesn't seem to post. Not sure where i went wrong.
wp.newPost( :blog_id => 0, # 0 unless using WP Multi-Site, then use the blog id
:content => {
:post_status => "publish",
:post_date => Time.now,
:post_content => "This is the body",
:post_title => "RubyPress is the best!",
:post_name => "/rubypress-is-the-best",
:post_author => 1, # 1 if there is only the admin user, otherwise the user's id
:terms_names => {
:category => ['Category One','Category Two','Category Three'],
:post_tag => ['Tag One','Tag Two', 'Tag Three']
}
}
)
Note: This is from the rubypress github page. Those categories and tags are not present on the blog, is that the reason?
host must be a host name (e.g. "localhost" in this particular case, or, say, "google.com"):
require 'rubypress'
wp = Rubypress::Client.new(host: "localhost",
username: "admin",
password: "admin",
path: "/wordpress/xmlrpc.php")
Probably, you might need to tune the path parameter up to point exactly to where WP’s RPC endpoint is to be found.

Shibboleth authentication in Rails

I am having a struggle getting this to work so I've created a hell-world Rails app to try and get this to work.
Here's the repo with the code that is not working: https://github.com/pitosalas/shibtry
Here's what I've done starting from an empty Rails application:
I've added two gems to gem files:
gem 'omniauth-shibboleth'
gem 'rack-saml'
I got the shibboleth meta data from my university's web site and converted it using shib_conv.rb into the corresponding YAML: ./config.yml
I've updated routes adding get '/auth/:provider/callback', to: 'sessions#create'
I've put a breakpoint at SessionController#create
I've added initializers: omniauth.rb:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :shibboleth, {
:shib_session_id_field => "Shib-Session-ID",
:shib_application_id_field => "Shib-Application-ID",
:debug => true,
:extra_fields => [
:"unscoped-affiliation",
:entitlement
]
}
end
I've added rack_sam.rb initializer:
Rails.application.config.middleware.insert_after Rack::ETag, Rack::Saml,
{ :metadata => "#{Rails.root}/config/metadata.yml"}
Now, run the server and go to http://0.0.0.0:3000/auth/shibboleth and I get an error:
undefined method `[]' for nil:NilClass'
which is traced back to this line in rack-saml/misc/onelogin_setting.rb line 13 which is:
settings.idp_sso_target_url = #metadata['saml2_http_redirect']
in other words, looking for the metadata hash for that key. It happens that in my metadata.yml file that key is present, but by the time I get to this onelogin_setting.rb line 13, #metadata is nil (it should contain the contents of the file) and consequently that key doesn't exist.
And that's where, for now, the trail dries up.
I bypassed Shibboleth totally. My goal was to allow login to my universities authentication system specifically to allow students to log in with their student login, which is fronted by google apps. So this was much easier: https://developers.google.com/identity/sign-in/web/
Looks like you forgot to add your config file to the initializer:
Rails.application.config.middleware.insert_after Rack::ETag, Rack::Saml,
{
:metadata => "#{Rails.root}/config/metadata.yml",
:config => "#{Rails.root}/config/rack-saml.yml"
}
And the saml_idp setting in the rack-saml.yml must match the key for the idp_lists entry in your metadata.yml

With Zabbix API, how do I get the values of items/resources rather than just the ID's?

I have some data in a Custom Screen in Zabbix, and would like to pull the data from the screen via the API. I'm using this Ruby gem: https://github.com/express42/zabbixapi
I'm able to successfully connect and query, but the results I'm getting are not very useful:
p zbx.query(
:method => "item.get",
:params => {
:itemids => "66666",
:output => "extend"
}
)
# [{"itemid"=>"66666", "type"=>"0", "snmp_community"=>"", "snmp_oid"=>"", "hostid"=>"77777", "name"=>"Fro Packages", "key_"=>"system.sw.packages[davekey1|davekey2|davekey3|davekey4]", "delay"=>"300", "history"=>"90", "trends"=>"365", "status"=>"0", "value_type"=>"1", "trapper_hosts"=>"", "units"=>"", "multiplier"=>"0", "delta"=>"0", "snmpv3_securityname"=>"", "snmpv3_securitylevel"=>"0", "snmpv3_authpassphrase"=>"", "snmpv3_privpassphrase"=>"", "formula"=>"1", "error"=>"", "lastlogsize"=>"0", "logtimefmt"=>"", "templateid"=>"88888", "valuemapid"=>"0", "delay_flex"=>"", "params"=>"", "ipmi_sensor"=>"", "data_type"=>"0", "authtype"=>"0", "username"=>"", "password"=>"", "publickey"=>"", "privatekey"=>"", "mtime"=>"0", "flags"=>"0", "filter"=>"", "interfaceid"=>"25", "port"=>"", "description"=>"", "inventory_link"=>"0", "lifetime"=>"30", "snmpv3_authprotocol"=>"0", "snmpv3_privprotocol"=>"0", "state"=>"0", "snmpv3_contextname"=>""}]
You can see that it's returning a bunch of ID's for the items, including the correct keys, but I can't seem to get the actual plain text values, which is the data I'm interested in.
I started with the screen_id, then got the screenitem_id, now the item_id, but I don't seem to be getting any closer to what I want!
Thanks for any help
Getting items or getting hosts means getting their description, not the data. is You are after history. Reading the actual Zabbix user manual and API docs is highly recommended.

Using Ruby & Github API to filter commits by date

I am using the ruby gem 'octokit' which implements the Github API v3. Mostly works great but I cannot seem to filter by date. I believe I have the syntax and time format correct, but it appears my option is ignored and the API returns the past 35 entries regardless of the since or until dates.
Here's a minimal reproducible example (after installing the octokit gem).
require 'octokit'
require 'time'
#day = "2012-09-27"
#until = DateTime.parse(#date).iso8601
#since = (DateTime.parse(#day) - 60*60*48).iso8601
a = Octokit.commits({:username => "cboettig", :repo => "labnotebook", :since => #since, :until => #until})
see the date of the output of last entry
a.last.commit.author.date
explicit day doesn't work either
b = Octokit.commits({:username => "cboettig", :repo => "labnotebook", :since => "2012-09-27T00:00:00+00:00"})
b.last.commit.author.date
The date I get in both examples is from August, outside the specified range given. What did I miss?
Background: I'm trying to write a little Jekyll plugin that uses the API to return commits made to a specified repo on the day of the post.
joeyw gives a great answer to this question here.
The second argument should be the sha or branch, and options should be the third argument, e.g.
Octokit.commits("cboettig/labnotebook", "master", :since => "2012-09-28T00:00:00+00:00").length
or
Octokit.commits("cboettig/labnotebook", nil, :since => "2012-09-28T00:00:00+00:00").length
works just fine. Here's my corresponding jekyll plugin

Get AWS region names with Ruby

I am developing a Rails application for AWS and would like to create drop down menu for region names, like "us-east-1" etc.
If someone already created gem to get them, I want to use it. Does anyone know such a gem or useful API?
The AWS SDK for Ruby (aws-sdk gem) supports enumerating region names:
require 'aws-sdk'
ec2 = AWS::EC2.new(:access_key_id => '...', :secret_access_key => '...')
ec2.regions.map(&:name)
=> ["eu-west-1", "sa-east-1", "us-east-1", "ap-northeast-1", "us-west-2", "us-west-1", "ap-southeast-1"]
You can also use a client interface to the DescribeRegions call:
ec2.client.describe_regions
=> { :region_info=>[
{:region_name=>"eu-west-1", :region_endpoint=>"ec2.eu-west-1.amazonaws.com"},
{:region_name=>"sa-east-1", :region_endpoint=>"ec2.sa-east-1.amazonaws.com"},
{:region_name=>"us-east-1", :region_endpoint=>"ec2.us-east-1.amazonaws.com"},
{:region_name=>"ap-northeast-1", :region_endpoint=>"ec2.ap-northeast-1.amazonaws.com"},
{:region_name=>"us-west-2", :region_endpoint=>"ec2.us-west-2.amazonaws.com"},
{:region_name=>"us-west-1", :region_endpoint=>"ec2.us-west-1.amazonaws.com"},
{:region_name=>"ap-southeast-1", :region_endpoint=>"ec2.ap-southeast-1.amazonaws.com"}
],
:request_id=>"04458cac-bdf2-4847-bf1f-c7ea65813777"
}
You can view the gem docs here: http://docs.amazonwebservices.com/AWSRubySDK/latest/frames.html
On mine I can do:
>> `ec2-describe-regions`.scan(/REGION\s+(\S+)/).flatten
=> ["eu-west-1", "sa-east-1", "us-east-1", "ap-northeast-1", "us-west-2", "us-west-1", "ap-southeast-1"]
I found the Gem!
http://rubydoc.info/gems/aws/2.5.6/Aws/Ec2:describe_regions

Resources