node-meraki
Version:
Meraki wrapper for nodejs
167 lines (151 loc) • 6.59 kB
JavaScript
const _ = require('lodash')
// const SessionStore = require('./src/dashboard/sessionStore')
// const { extractEid } = require('./src/utils')
const apiKey = '0e00d34e01d1f92d1d40ea991a9840799777dd71'
// const orgId = '730666'
const orgId = '682858293500054805'
const version = 'v0'
const rateLimiter = { enabled: true, scoped: true }
const baseUrl = 'https://n213.meraki.com'
const email = 'devops@zebbra.ch'
const password = 'wlK{KjuD8vzwyLWP'
// const email = 'michael.baertschi@zebbra.ch'
// const password = 'vFWQBtCTZ#oPHd8Y'
const dashboardApiEnabled = true
const keepAlive = false
const serial = 'Q2MN-Y8CM-HLVE'
const switchSerial = 'Q2RX-3GPP-FYPZ'
const networkId = 'L_682858293500060703'
const wifiDeviceSerial = 'Q2RD-7FCL-N727'
const clientMac = '88:e9:fe:63:fe:93'
const configTemplateId = 'L_682858293500063507'
const target = 'n213'
const settings = {
version,
apiKey,
target,
organizationId: orgId,
baseUrl,
rateLimiter,
dashboardApiEnabled,
email,
password,
keepAlive,
loggerEnabled: true
}
const meraki = require('./src')(settings)
function handleErrors (error) {
if (error.response) {
console.log('\n------------- Error response -------------')
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
console.log('data:', error.response.data)
console.log('status:', error.response.status)
console.log('headers:', error.response.headers)
} else if (error.request) {
console.log('\n------------- Error response -------------')
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
// http.ClientRequest in node.js
console.log(error.request)
} else {
console.log('\n------------- Error message -------------')
// Something happened in setting up the request that triggered an Error
console.log('Error', error.message)
}
console.log('\n------------- Error config -------------')
console.log(error.config)
}
// meraki.listNetworkVLANs({ networkId: 'L_682858293500070034' }).catch(handleErrors)
meraki.getRaw({
path: '/api/v0/organizations/682858293500054805/configTemplates',
priority: 0
})
// meraki.moveDevices({ networkId: 'L_682858293500067996', newNetwork: 'L_682858293500067997', serials: ['Q2EX-VW8G-TKRP']}).then(console.log).catch(handleErrors)
// meraki.showOrganization({ orgId: "682858293500054376" }).then(console.log)
// meraki.listOrganizations().then(console.log)
// meraki.showSamlRole({ orgId: '682858293500054481', roleId: 'UkVBRF9PTkxZ' }).then(console.log)
// let samlRole
// meraki
// .showOrganization({ orgId: "682858293500054481" })
// .then(() => meraki.listSamlRoles({ orgId: '682858293500054481' }))
// .then(() => meraki.createSamlRole({ orgId: '682858293500054481', role: 'READ_ONLY_USER', orgAccess: 'read-only' }))
// .then((role) => (samlRole = role))
// .then(() => meraki.showOrganization({ orgId: '682858293500054481'}))
// .then(() => meraki.listSamlRoles({ orgId: '682858293500054481' }))
// .then(() => meraki.deleteSamlRole({ orgId: '682858293500054481', roleId: samlRole.id}))
// meraki.deleteSamlRole({ orgId: '682858293500054481', roleId: 'UkVBRF9PTkxZX1VTRVI=' })
// meraki.updateSamlRole({ orgId: '682858293500054481', roleId: 'UkVBRF9PTkxZ' }).then(console.log)
// meraki.cloneOrganization({ orgId: 730666, name: 'Test Michu' }).then(console.log).catch(handleErrors)
// meraki.listNetworks({ orgId: '682858293500054481' }).then(console.log)
// meraki.listNetworkDevices({ networkId: 'L_682858293500067996' }).then(console.log)
// meraki.showNetwork({ networkId: 'L_682858293500067034' }).then(console.log)
// meraki.listMxL3FirewallRules({ networkId: 'L_682858293500067122' }).then(console.log)
// meraki.listMxL3FirewallRules({ networkId: 'L_682858293500067121' }).then(console.log)
// meraki.listSiteToSiteVpn({ networkId: 'L_682858293500067121' }).then(console.log).catch(handleErrors)
// meraki.updateSiteToSiteVpn({ networkId: 'L_682858293500067121', mode: 'hub' })
// meraki.listSwitchPorts({ deviceSerial: 'Q2RX-3GPP-FYPZ' }).then(console.log)
// meraki.deleteNetwork({ networkId: 'L_682858293500068978' }).catch(console.error)
// meraki.updateAlertSettings({ networkId: 'L_682858293500068987', defaultDestinations: { httpServerIds: ['aHR0cHM6Ly80ZmZmZWY4MC5uZ3Jvay5pby9hbGVydHMvbWVyYWtp'] } }).catch(console.log)
// meraki
// .updateMxL3FirewallRule({ networkId: 'L_682858293500067033', rules: []})
// .then(console.log)
// .catch(handleErrors)
// const cleanOrgs = (orgs) => {
// return Promise
// .all(orgs.map(({ id: orgId }) => {
// return meraki
// .listNetworks({ orgId })
// .then((networks) => {
// console.log('networks', networks)
// return Promise.all(networks.map(({ id: networkId }) => meraki.deleteNetwork({ networkId })))
// })
// .then((res) => {
// console.log(res)
// return meraki.listConfigurationTemplates({ orgId })
// })
// .then((templates) => {
// console.log('templates', templates)
// return Promise.all(templates.map(({ id: templateId }) => meraki.deleteConfigurationTemplate({ orgId, templateId })))
// })
// .then((res) => {
// console.log(res)
// return meraki.listAdmins({ orgId })
// })
// }))
// }
// meraki
// // .cloneOrganization({ orgId, name: 'Test Clone 2' })
// // .then(() => meraki.listOrganizations())
// .listOrganizations()
// // .then((orgs) => {
// // console.log(orgs)
// // return orgs
// // })
// .then((orgs) => {
// const del_orgs = orgs
// // .filter((org) => org.name.startsWith('Test Clone'))
// // .filter((org) => org.name.startsWith('Sunrise BC Test Team'))
// .filter((org) => org.name.startsWith('Gemeindeverwaltung Itingen'))
// // .filter((org) => org.id === '682858293500053716')
// .map((org) => {
// org.eid = extractEid(org.samlConsumerUrl)
// return org
// })
// return cleanOrgs(del_orgs)
// .then(() => Promise
// .all(del_orgs.map(({ eid }) => {
// console.log(eid)
// return meraki.deleteOrganizationDashboard({ eid })
// })
// )
// )
// })
// .then(console.log)
// .catch(handleErrors)
// const store = new SessionStore(baseUrl, email, password, keepAlive)
// const eid = 'fpNHwdvd'
// store
// .get(eid)
// .then(() => console.log(store.store))
// .catch(console.error)