Skip to content

Instantly share code, notes, and snippets.

View cw2908's full-sized avatar
🙃
---

cw2908

🙃
---
View GitHub Profile
@cw2908
cw2908 / import_whd_tickets.rb
Last active May 5, 2020 15:32
Import Incidents from WHD export
# frozen_string_literal: true
#################################################################
##
## First install the api wrapper & xmlparser `gem install samanage nokogiri`
## To run `ruby import_whd_tickets.rb api-token export-file.csv`
##
##
## The CSV input columns were:
##
@cw2908
cw2908 / simple_site_export.rb
Last active September 26, 2019 17:01
Simple Script for exporting sites to csv
## To run: 'gem install samanage' then 'ruby simple_site_export.rb API_TOKEN' or replace 12345 below with your token
require 'samanage'
token = ARGV[0] || '12345'
@samanage = Samanage::Api.new(token: token)
def log_to_csv(row: , filename: 'Sites Export.csv')
write_headers = !File.exists?(filename)
CSV.open(filename, 'a+', write_headers: write_headers, force_quotes: true, headers: row.keys) do |csv|
csv << row.values

First install Ruby 2.6 or higher. Then gem install samanage

Run from the command:

ruby script_name.rb API_TOKEN 2018-01-01 2018-12-31 or ruby script_name.rb API_TOKEN 2018-01-01 2018-12-31 eu if on the EU datacenter.

@cw2908
cw2908 / export_incidents.rb
Last active March 13, 2020 14:54
Samanage Format Export
# Export incidents within date range
#
# First install the lastest Ruby version and our library via command `gem install samanage`
#
# Run with the command: `ruby script_name.rb API_TOKEN 2019-01-01 2019-12-31`
# or in the EU datacenter `ruby script_name.rb API_TOKEN 2019-01-01 2019-12-31 eu`
require 'samanage'
require 'csv'