Giter Site home page Giter Site logo

samanage-ruby's People

Contributors

cw2908 avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

samanage-ruby's Issues

How to Filter ticket by Ticket State

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'

ruby script_name.rb API_TOKEN 2019-01-01 2019-12-31

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',

}

Request and save incidents

@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

Escape HTTP::ConnectionError

/.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)

Samanage Extract Incidents

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.