cw2908 / samanage-ruby Goto Github PK
View Code? Open in Web Editor NEWSamanage Ruby Gem
License: GNU General Public License v3.0
Samanage Ruby Gem
License: GNU General Public License v3.0
Hi Chris, @cw2908
How I can add another query to filter by State?
For example ticket CREATED from January 1, 2018 to current date AND
filter only tickets that with 'State' = 'Assigned', 'New','OnHold','Third Party' etc?
AND another query to filter by ResolvedAT or ClosedAt
from January 1, 2018 to current date and State = 'Resolved' or 'Closed'
Thank you!
require 'samanage'
require 'csv'
api_token, start_date, end_date, datacenter = ARGV
@SAManage = Samanage::Api.new(token: api_token, datacenter: datacenter)
DEFAULT_FILENAME = "Incident Report #{DateTime.now.strftime("%b-%d-%Y-%l%M")}.csv"
#Simple CSV writer
def log_to_csv(row: , filename: DEFAULT_FILENAME, headers: )
write_headers = !File.exists?(filename)
CSV.open(filename, 'a+', write_headers: write_headers, force_quotes: true, headers: headers) do |csv|
csv << row
end
end
#Save specific fields from incident and flatten to key pair
def format_incident(incident: )
{
id: incident.dig('id'),
number: incident.dig('number'),
name: incident.dig('name'),
state: incident.dig('state'),
assignee: incident.dig('assignee','name'), # I picked assignee->name because groups do not have an email
requester: incident.dig('requester','email'), # All requesters have email
created_at: incident.dig('created_at'), # All requesters have email
updated_at: incident.dig('updated_at'), # All requesters have email
category: incident.dig('category','name'), # All requesters have email
sucategory: incident.dig('category','name'), # All requesters have email
siteid: incident.dig('site','id'), # All requesters have email
sitename: incident.dig('site','name'), # All requesters have email
sitelocation: incident.dig('site','location'), # All requesters have email
reports_to: incident.dig('assignee','reports_to','id') # All requesters have email
}
end
query_options = {
'created[]' => 'Select Date Range',
'created_custom_gte[]' => start_date,
'created_custom_lte[]' => end_date,
'layout' => 'long',
}
@samanage.incidents(options: query_options).map do |incident|
csv_data = format_incident(incident: incident)
log_to_csv(row: csv_data.values, headers: csv_data.keys)
end
/.rvm/gems/ruby-2.3.1/gems/http-2.2.2/lib/http/timeout/null.rb:26:in `connect': failed to connect: Connection reset by peer - SSL_connect (HTTP::ConnectionError)
Quick patched the Samanage::Api.execute(... ssl_fix: false)
to solve Certificate Error issue in HTTP. Used in /lib/api.rb
Hi Chris W @cw2908,
Good Day!
May I ask if you have sample ruby scripts to extract incidents in Samanage with date coverage parameter?
Thank you in advance!
Regards,
Ron
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.