| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950 |
- # Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved
- #
- # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
- # except in compliance with the License. You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software distributed under the
- # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
- # either express or implied. See the License for the specific language governing permissions
- # and limitations under the License.
- """
- This module provides a client class for BCM.
- """
- import copy
- import json
- import sys
- import uuid
- from baidubce import bce_base_client, utils, compat
- from baidubce.auth import bce_v1_signer
- from baidubce.http import handler, bce_http_client, http_methods
- from baidubce.services.bcm import bcm_handler, bcm_model
- from baidubce.utils import required
- if sys.version_info[0] == 2:
- value_type = (str, unicode)
- else:
- value_type = (str, bytes)
- MAX_INSTANCE_NUMBER = 100
- class BcmClient(bce_base_client.BceBaseClient):
- """
- BCM base sdk client
- """
- prefix = b'/json-api'
- csm_prefix = b'/csm/api'
- event_prefix = b'/event-api'
- version = b'/v1'
- version_v2 = b'/v2'
- content_type_header_key = b"content-type"
- content_type_header_value = b"application/json;charset=UTF-8"
- request_id_header_key = b"x-bce-request-id"
- def __init__(self, config=None):
- bce_base_client.BceBaseClient.__init__(self, config)
- def _merge_config(self, config=None):
- if config is None:
- return self.config
- else:
- new_config = copy.copy(self.config)
- new_config.merge_non_none_values(config)
- return new_config
- def _send_request(self, http_method, path,
- body=None, headers=None, params=None,
- config=None, body_parser=None):
- config = self._merge_config(config)
- if body_parser is None:
- body_parser = handler.parse_json
- return bce_http_client.send_request(
- config, bce_v1_signer.sign, [handler.parse_error, body_parser],
- http_method, BcmClient.prefix + BcmClient.version + path, body, headers, params)
- def _send_csm_request(self, http_method, path, version=b'/v1',
- body=None, headers=None, params=None, config=None, body_parser=None):
- config = self._merge_config(config)
- if body_parser is None:
- body_parser = handler.parse_json
- if headers is None:
- headers = {}
- if self.content_type_header_key not in headers:
- headers[self.content_type_header_key] = self.content_type_header_value
- if self.request_id_header_key not in headers:
- headers[self.request_id_header_key] = uuid.uuid4()
- return bce_http_client.send_request(
- config, bce_v1_signer.sign, [bcm_handler.parse_error, body_parser],
- http_method, BcmClient.csm_prefix + version + path, body, headers, params)
- def _send_event_request(self, http_method, path,
- body=None, headers=None, params=None, config=None, body_parser=None):
- config = self._merge_config(config)
- if body_parser is None:
- body_parser = handler.parse_json
- if headers is None:
- headers = {}
- if self.content_type_header_key not in headers:
- headers[self.content_type_header_key] = self.content_type_header_value
- if self.request_id_header_key not in headers:
- headers[self.request_id_header_key] = uuid.uuid4()
- return bce_http_client.send_request(
- config, bce_v1_signer.sign, [bcm_handler.parse_error, body_parser],
- http_method, BcmClient.event_prefix + BcmClient.version + path, body, headers, params)
- def get_metric_data(self, user_id=None, scope=None, metric_name=None,
- dimensions=None, statistics=None, start_time=None,
- end_time=None, period_in_second=None, config=None):
- """
- Return metric data of product instances owned by the authenticated user.
- This site may help you: https://cloud.baidu.com/doc/BCM/s/9jwvym3kb
- :param user_id:
- Master account ID
- :type user_id: string
- :param scope:
- Cloud product namespace, eg: BCE_BCC.
- :type scope: string
- :param metric_name:
- The metric name of baidu cloud monitor, eg: CpuIdlePercent.
- :type metric_name: string
- :param dimensions:
- Consists of dimensionName: dimensionValue.
- Use semicolons when items have multiple dimensions,
- such as dimensionName: dimensionValue; dimensionName: dimensionValue.
- Only one dimension value can be specified for the same dimension.
- eg: InstanceId:fakeid-2222
- :type dimensions: string
- :param statistics:
- According to the format of statistics1,statistics2,statistics3,
- the optional values are `average`, `maximum`, `minimum`, `sum`, `sampleCount`
- :type statistics: string
- :param start_time:
- Query start time.
- Please refer to the date and time, UTC date indication
- :type start_time: string
- :param end_time:
- Query end time.
- Please refer to the date and time, UTC date indication
- :type end_time: string
- :param period_in_second:
- Statistical period.
- Multiples of 60 in seconds (s).
- :type period_in_second: int
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- user_id = compat.convert_to_bytes(user_id)
- scope = compat.convert_to_bytes(scope)
- metric_name = compat.convert_to_bytes(metric_name)
- path = b'/metricdata/%s/%s/%s' % (user_id, scope, metric_name)
- params = {}
- if dimensions is not None:
- params[b'dimensions'] = dimensions
- if statistics is not None:
- params[b'statistics[]'] = statistics
- if start_time is not None:
- params[b'startTime'] = start_time
- if end_time is not None:
- params[b'endTime'] = end_time
- if period_in_second is not None:
- params[b'periodInSecond'] = period_in_second
- return self._send_request(http_methods.GET, path, params=params, config=config)
- def get_batch_metric_data(self, user_id=None, scope=None, metric_name=None,
- dimensions=None, statistics=None, start_time=None,
- end_time=None, period_in_second=None, config=None):
- """
- Return batch metric data of product instances owned by the authenticated user.
- :param user_id:
- Master account ID
- :type user_id: string
- :param scope:
- Cloud product namespace, eg: BCE_BCC.
- :type scope: string
- :param metric_name:
- The metric name of baidu cloud monitor, eg: CpuIdlePercent.
- Use comma when items have multiple metrics,
- such as metric1,metric2,metric3.
- :type metric_name: string
- :param dimensions:
- Consists of dimensionName:dimensionValue.
- Use comma when items have multiple dimensions,
- such as dimensionName:dimensionValue,dimensionName:dimensionValue.
- Only one dimension value can be specified for the same dimension.
- eg: InstanceId:itk-1010,InstanceId:itk-1011
- :type dimensions: string
- :param statistics:
- According to the format of statistics1,statistics2,statistics3,
- the optional values are `average`, `maximum`, `minimum`, `sum`, `sampleCount`
- :type statistics: string
- :param start_time:
- Query start time.
- Please refer to the date and time, UTC date indication
- :type start_time: string
- :param end_time:
- Query end time.
- Please refer to the date and time, UTC date indication
- :type end_time: string
- :param period_in_second:
- Statistical period.
- Multiples of 60 in seconds (s).
- :type period_in_second: int
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- user_id = compat.convert_to_bytes(user_id)
- scope = compat.convert_to_bytes(scope)
- path = b'/metricdata/batch/%s/%s' % (user_id, scope)
- params = {}
- if metric_name is not None:
- params[b'metricName[]'] = metric_name
- if dimensions is not None:
- params[b'dimensions[]'] = dimensions
- if statistics is not None:
- params[b'statistics[]'] = statistics
- if start_time is not None:
- params[b'startTime'] = start_time
- if end_time is not None:
- params[b'endTime'] = end_time
- if period_in_second is not None:
- params[b'periodInSecond'] = period_in_second
- return self._send_request(http_methods.GET, path, params=params, config=config)
- def create_namespace(self, user_id, name, namespace_alias=None, comment=None, config=None):
- """
- create a custom namespace for custom monitor
- This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
- :param user_id:
- master account id
- :type user_id: string
- :param name:
- namespace name
- :type name: string
- :param namespace_alias:
- namespace alias name
- :type namespace_alias: string
- :param comment:
- namespace comment
- :type user_id: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(name) <= 0:
- raise ValueError('name should not be none or empty string')
- path = b'/userId/%s/custom/namespaces/create' % compat.convert_to_bytes(user_id)
- body = {
- "userId": user_id,
- "name": name,
- "namespaceAlias": namespace_alias,
- "comment": comment,
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def batch_delete_namespaces(self, user_id, names, config=None):
- """
- create a custom namespace for custom monitor
- This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
- :param user_id:
- master account id
- :type user_id: string
- :param names:
- namespace name collection
- :type names: string array
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(names) <= 0:
- raise ValueError('names should not be empty')
- path = b'/userId/%s/custom/namespaces/delete' % compat.convert_to_bytes(user_id)
- body = {
- "userId": user_id,
- "names": names,
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def update_namespace(self, user_id, name, namespace_alias=None, comment=None, config=None):
- """
- update a custom namespace for custom monitor
- This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
- :param user_id:
- master account id
- :type user_id: string
- :param name:
- namespace name
- :type name: string
- :param namespace_alias:
- namespace alias name
- :type namespace_alias: string
- :param comment:
- namespace comment
- :type user_id: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(name) <= 0:
- raise ValueError('name should not be none or empty string')
- path = b'/userId/%s/custom/namespaces/update' % compat.convert_to_bytes(user_id)
- body = {
- "userId": user_id,
- "name": name,
- "namespaceAlias": namespace_alias,
- "comment": comment,
- }
- return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
- def list_namespaces(self, user_id, name=None, page_no=None, page_size=None, config=None):
- """
- list custom namespaces
- This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
- :param user_id:
- master account id
- :type user_id: string
- :param name:
- namespace name prefix for query
- :type name: string
- :param page_no:
- page number
- :type page_no: int
- :param page_size:
- page size
- :type page_size: int
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- path = b'/userId/%s/custom/namespaces/list' % compat.convert_to_bytes(user_id)
- params = {
- b'userId': user_id,
- }
- if name is not None:
- params[b'name'] = name
- if page_no is None:
- params[b'pageNo'] = 1
- else:
- params[b'pageNo'] = page_no
- if page_size is None:
- params[b'pageSize'] = 10
- else:
- params[b'pageSize'] = page_size
- return self._send_csm_request(http_methods.GET, path, params=params, config=config)
- def create_namespace_metric(self, user_id, namespace, metric_name,
- metric_alias=None, unit=None, cycle=None, dimensions=None, config=None):
- """
- create custom metric in one namespace
- This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
- :param user_id:
- master account id
- :type user_id: string
- :param namespace:
- namespace name
- :type namespace: string
- :param metric_name:
- custom metric name
- :type metric_name: string
- :param metric_alias:
- custom metric alias
- :type metric_alias: string
- :param unit:
- custom metric unit
- :type unit: string
- :param unit:
- custom metric unit
- :type unit: string
- :param cycle:
- custom metric cycle
- :type cycle: int
- :param dimensions:
- custom dimension collection
- :type dimensions: CustomDimensionModel array
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(namespace) <= 0:
- raise ValueError('namespace should not be none or empty string')
- if len(metric_name) <= 0:
- raise ValueError('metric_name should not be none or empty string')
- path = (b'/userId/%s/custom/namespaces/%s/metrics/create' %
- (compat.convert_to_bytes(user_id), compat.convert_to_bytes(namespace)))
- body = {
- "userId": user_id,
- "namespace": namespace,
- "metricName": metric_name,
- }
- if metric_alias is not None:
- body["metricAlias"] = metric_alias
- if unit is not None:
- body["unit"] = unit
- if cycle is not None:
- body["cycle"] = cycle
- else:
- body["cycle"] = 60
- if dimensions is not None:
- body["dimensions"] = dimensions
- else:
- body["dimensions"] = []
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def batch_delete_namespace_metrics(self, user_id, namespace, ids, config=None):
- """
- batch delete custom metric in one namespace
- This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
- :param user_id:
- master account id
- :type user_id: string
- :param namespace:
- custom namespace name
- :type namespace: string
- :param ids:
- namespace metric id collection
- :type ids: int array
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(ids) <= 0:
- raise ValueError('ids should not be empty')
- path = (b'/userId/%s/custom/namespaces/%s/metrics/delete' %
- (compat.convert_to_bytes(user_id), compat.convert_to_bytes(namespace)))
- body = {
- "userId": user_id,
- "namespace": namespace,
- "ids": ids,
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def update_namespace_metric(self, user_id, namespace, metric_name,
- metric_alias=None, unit=None, cycle=None, dimensions=None, config=None):
- """
- update custom metric in one namespace
- This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
- :param user_id:
- master account id
- :type user_id: string
- :param namespace:
- namespace name
- :type namespace: string
- :param metric_name:
- custom metric name
- :type metric_name: string
- :param metric_alias:
- custom metric alias
- :type metric_alias: string
- :param unit:
- custom metric unit
- :type unit: string
- :param unit:
- custom metric unit
- :type unit: string
- :param cycle:
- custom metric cycle
- :type cycle: int
- :param dimensions:
- custom dimension collection
- :type dimensions: CustomDimensionModel array
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(namespace) <= 0:
- raise ValueError('namespace should not be none or empty string')
- if len(metric_name) <= 0:
- raise ValueError('metric_name should not be none or empty string')
- if cycle is None:
- raise ValueError('cycle should not be none')
- path = (b'/userId/%s/custom/namespaces/%s/metrics/%s' % (compat.convert_to_bytes(user_id),
- compat.convert_to_bytes(namespace),
- compat.convert_to_bytes(metric_name)))
- body = {
- "userId": user_id,
- "namespace": namespace,
- "metricName": metric_name,
- "cycle": cycle,
- }
- if metric_alias is not None:
- body["metricAlias"] = metric_alias
- if unit is not None:
- body["unit"] = unit
- if dimensions is not None:
- body["dimensions"] = dimensions
- return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
- def list_namespace_metrics(self, user_id, namespace,
- metric_name=None, metric_alias=None, page_no=None, page_size=None, config=None):
- """
- list custom metric in one namespace
- This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
- :param user_id:
- master account id
- :type user_id: string
- :param namespace:
- namespace name
- :type namespace: string
- :param metric_name:
- custom metric name prefix for query
- :type metric_name: string
- :param metric_alias:
- custom metric alias prefix for query
- :type metric_alias: string
- :param page_no:
- page number
- :type page_no: int
- :param page_size:
- page size
- :type page_size: int
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(namespace) <= 0:
- raise ValueError('namespace should not be none or empty string')
- path = b'/userId/%s/custom/namespaces/metrics' % compat.convert_to_bytes(user_id)
- params = {
- b'userId': user_id,
- b'namespace': namespace,
- }
- if metric_name is not None:
- params[b'metricName'] = metric_name
- if metric_alias is not None:
- params[b'metricAlias'] = metric_alias
- if page_no is None:
- params[b'pageNo'] = 1
- else:
- params[b'pageNo'] = page_no
- if page_size is None:
- params[b'pageSize'] = 10
- else:
- params[b'pageSize'] = page_size
- return self._send_csm_request(http_methods.GET, path, params=params, config=config)
- def get_custom_metric(self, user_id, namespace, metric_name, config=None):
- """
- get custom metric detail
- This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
- :param user_id:
- master account id
- :type user_id: string
- :param namespace:
- namespace name
- :type namespace: string
- :param metric_name:
- custom metric name
- :type metric_name: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(namespace) <= 0:
- raise ValueError('namespace should not be none or empty string')
- if len(metric_name) <= 0:
- raise ValueError('metric_name should not be none or empty string')
- path = (b'/userId/%s/custom/namespaces/%s/metrics/%s' % (compat.convert_to_bytes(user_id),
- compat.convert_to_bytes(namespace),
- compat.convert_to_bytes(metric_name)))
- params = {}
- return self._send_csm_request(http_methods.GET, path, params=params, config=config)
- def create_namespace_event(self, user_id, namespace, event_name, event_level,
- event_name_alias=None, comment=None, config=None):
- """
- create custom event in one namespace
- This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
- :param user_id:
- master account id
- :type user_id: string
- :param namespace:
- namespace name
- :type namespace: string
- :param event_level:
- custom event level
- :type event_level: ENUM {'NOTICE', 'WARNING', 'MAJOR', 'CRITICAL'}
- :param event_name:
- custom event name
- :type event_name: string
- :param event_name_alias:
- custom event alias
- :type event_name_alias: string
- :param comment:
- custom event comment
- :type comment: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(namespace) <= 0:
- raise ValueError('namespace should not be none or empty string')
- if len(event_name) <= 0:
- raise ValueError('event_name should not be none or empty string')
- if not bcm_model.EventLevel.contains(event_level):
- raise ValueError('event_level must be one of %s' % str(bcm_model.EventLevel.all_event_levels()))
- path = b'/custom/event/configs/create'
- body = {
- "userId": user_id,
- "namespace": namespace,
- "eventName": event_name,
- "eventLevel": event_level,
- }
- if event_name_alias is not None:
- body["eventNameAlias"] = event_name_alias
- if comment is not None:
- body["comment"] = comment
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def batch_delete_namespace_events(self, user_id, namespace, names, config=None):
- """
- batch delete custom metric in one namespace
- This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
- :param user_id:
- master account id
- :type user_id: string
- :param namespace:
- custom namespace name
- :type namespace: string
- :param names:
- namespace event name collection
- :type names: string array
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(names) <= 0:
- raise ValueError('names should not be empty')
- path = b'/custom/event/configs/delete'
- body = {
- "userId": user_id,
- "namespace": namespace,
- "names": names,
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def update_namespace_event(self, user_id, namespace, event_name, event_level,
- event_name_alias=None, comment=None, config=None):
- """
- update custom event in one namespace
- This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
- :param user_id:
- master account id
- :type user_id: string
- :param namespace:
- namespace name
- :type namespace: string
- :param event_level:
- custom event level
- :type event_level: ENUM {'NOTICE', 'WARNING', 'MAJOR', 'CRITICAL'}
- :param event_name:
- custom event name
- :type event_name: string
- :param event_name_alias:
- custom event alias
- :type event_name_alias: string
- :param comment:
- custom event comment
- :type comment: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(namespace) <= 0:
- raise ValueError('namespace should not be none or empty string')
- if len(event_name) <= 0:
- raise ValueError('event_name should not be none or empty string')
- if not bcm_model.EventLevel.contains(event_level):
- raise ValueError('event_level must be one of %s' % str(bcm_model.EventLevel.all_event_levels()))
- path = b'/custom/event/configs/update'
- body = {
- "userId": user_id,
- "namespace": namespace,
- "eventName": event_name,
- "eventLevel": event_level,
- }
- if event_name_alias is not None:
- body["eventNameAlias"] = event_name_alias
- if comment is not None:
- body["comment"] = comment
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def list_namespace_events(self, user_id, namespace,
- name=None, event_level=None, page_no=None, page_size=None, config=None):
- """
- list custom event in one namespace
- This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
- :param user_id:
- master account id
- :type user_id: string
- :param namespace:
- namespace name
- :type namespace: string
- :param name:
- custom metric name prefix for query
- :type name: string
- :param event_level:
- custom metric level
- :type event_level: None or ENUM {'NOTICE', 'WARNING', 'MAJOR', 'CRITICAL'}
- :param page_no:
- page number
- :type page_no: int
- :param page_size:
- page size
- :type page_size: int
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(namespace) <= 0:
- raise ValueError('namespace should not be none or empty string')
- if event_level is not None and (not bcm_model.EventLevel.contains(event_level)):
- raise ValueError('event_level must be none or one of %s' % str(bcm_model.EventLevel.all_event_levels()))
- path = b'/custom/event/configs/list'
- params = {
- b'userId': user_id,
- b'namespace': namespace,
- }
- if name is not None:
- params[b'name'] = name
- if event_level is not None:
- params[b'event_level'] = event_level
- if page_no is None:
- params[b'pageNo'] = 1
- else:
- params[b'pageNo'] = page_no
- if page_size is None:
- params[b'pageSize'] = 10
- else:
- params[b'pageSize'] = page_size
- return self._send_csm_request(http_methods.GET, path, params=params, config=config)
- def get_custom_event(self, user_id, namespace, event_name, config=None):
- """
- get custom event detail
- This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
- :param user_id:
- master account id
- :type user_id: string
- :param namespace:
- namespace name
- :type namespace: string
- :param event_name:
- custom event name
- :type event_name: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(namespace) <= 0:
- raise ValueError('namespace should not be none or empty string')
- if len(event_name) <= 0:
- raise ValueError('metric_name should not be none or empty string')
- path = b'/custom/event/configs/detail'
- params = {
- b"userId": user_id,
- b"namespace": namespace,
- b"eventName": event_name,
- }
- return self._send_csm_request(http_methods.GET, path, params=params, config=config)
- @required(page_no=int, page_size=int)
- def list_notify_group(self, page_no, page_size, name=None):
- """
- :param name: notify name
- :type name: string
- :param page_no: page number
- :type page_no: int
- :param page_size: page size
- :type page_size: int
- :return
- :rtype baidubce.bce_response.BceResponse
- """
- headers = {self.content_type_header_key: self.content_type_header_value}
- path = b'/alarm/notify/group/list'
- body = {
- "name": name,
- "pageNo": page_no,
- "pageSize": page_size
- }
- return self._send_request(http_methods.POST, path, headers=headers, body=json.dumps(body))
- @required(page_no=int, page_size=int)
- def list_notify_party(self, page_no, page_size, name=None):
- """
- :param name: notify name
- :type name: string
- :param page_no: page number
- :type page_no: int
- :param page_size: page size
- :type page_size: int
- :return
- :rtype baidubce.bce_response.BceResponse
- """
- headers = {self.content_type_header_key: self.content_type_header_value}
- path = b'/alarm/notify/party/list'
- body = {
- "name": name,
- "pageNo": page_no,
- "pageSize": page_size
- }
- return self._send_request(http_methods.POST, path, headers=headers, body=json.dumps(body))
- @required(page_no=int, page_size=int, notifications=list, members=list)
- def create_action(self, user_id, notifications, members, alias, disable_times=None, action_callbacks=None):
- """
- :param user_id:
- :type user_id: string
- :param notifications:
- :type notifications: list of bcm_model.Notification
- :param members:
- :type members: list of bcm_model.Member
- :param alias: action's alias
- :type alias: string
- :param disable_times: disable time
- :type disable_times: list of bcm_model.DisableTime
- :param action_callbacks: list of action callback
- :type action_callbacks: list
- :return
- :rtype baidubce.bce_response.BceResponse
- """
- if disable_times is None:
- disable_times = []
- if action_callbacks is None:
- action_callbacks = []
- path = b'/userId/%s/action/create' % compat.convert_to_bytes(user_id)
- body = {
- "userId": user_id,
- "notifications": notifications,
- "members": members,
- "alias": alias,
- "disableTimes": disable_times,
- "actionCallBacks": action_callbacks
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
- def delete_action(self, user_id, name):
- """
- :param user_id:
- :type user_id: string
- :param name: action name
- :type name: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/userId/%s/action/delete' % compat.convert_to_bytes(user_id)
- params = {b'name': name}
- return self._send_csm_request(http_methods.DELETE, path, params=params)
- @required(page_no=int, page_size=int)
- def list_action(self, user_id, page_no, page_size, name=None, order=None):
- """
- :param user_id:
- :type user_id: string
- :param page_no: page number
- :type page_no: int
- :param page_size: page size
- :type page_size: int
- :param name: action name
- :type name: string
- :param order: desc or asc
- :type name: string
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/userId/%s/action/actionList' % compat.convert_to_bytes(user_id)
- body = {
- "name": name,
- "pageNo": page_no,
- "pageSize": page_size,
- "order": order
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
- @required(page_no=int, page_size=int, notifications=list, members=list)
- def update_action(self, user_id, name, notifications, members, alias, disable_times=None,
- action_callbacks=None):
- """
- :param user_id:
- :type user_id: string
- :param name: action name
- :type name: string
- :param notifications:
- :type notifications: list of bcm_model.Notification
- :param members:
- :type members: list of bcm_model.Member
- :param alias: action's alias
- :type alias: string
- :param disable_times: disable time
- :type disable_times: list of bcm_model.DisableTime
- :param action_callbacks: list of action callback
- :type action_callbacks: list
- :return
- :rtype baidubce.bce_response.BceResponse
- """
- if disable_times is None:
- disable_times = []
- if action_callbacks is None:
- action_callbacks = []
- path = b'/userId/%s/action/update' % compat.convert_to_bytes(user_id)
- body = {
- "productName": user_id,
- "name": name,
- "notifications": notifications,
- "members": members,
- "alias": alias,
- "disableTimes": disable_times,
- "actionCallBacks": action_callbacks,
- "source": "USER"
- }
- return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body))
- def log_extract(self, user_id, extract_rule, log_example):
- """
- :param user_id:
- :type user_id: string
- :param extract_rule: the log extract rule
- :type: string
- :param log_example: log example
- :type: string
- :return
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/userId/%s/application/logextract' % compat.convert_to_bytes(user_id)
- body = {
- "extractRule": extract_rule,
- "logExample": log_example
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body),
- body_parser=bcm_handler.parse_json_list)
- def query_metric_meta_for_application(self, user_id, app_name, task_name, metric_name, dimension_keys,
- instances=None):
- """
- :param user_id:
- :type user_id string
- :param app_name: application name
- :type app_name: string
- :param task_name: task name
- :type task_name: string
- :param metric_name:
- :type metric_name: string
- :param dimension_keys: multi dimension keys
- :type dimension_keys: list of string
- :param instances: multiple instance names
- :type instances: list of string
- :return
- :rtype baidubce.bce_response.BceResponse
- """
- path = (b'/userId/%s/application/%s/task/%s/metricMeta' % (compat.convert_to_bytes(user_id),
- compat.convert_to_bytes(app_name),
- compat.convert_to_bytes(task_name)))
- params = {b'metricName': metric_name, b'dimensionKeys': ",".join(dimension_keys)}
- print(params)
- if instances is not None and len(instances) > 0:
- params[b'instances'] = ",".join(instances)
- return self._send_csm_request(http_methods.GET, path, params=params)
- def query_metric_data_for_application(self, user_id, app_name, task_name, metric_name, start_time, end_time,
- instances=None, cycle=None, dimensions=None, statistics=None, aggr_data=None):
- """
- :param user_id:
- :type user_id: string
- :param app_name: application name
- :type app_name: string
- :param task_name: task name
- :type task_name: string
- :param metric_name: metric name
- :type metric_name: string
- :param start_time: start time, such as 2023-12-05T09:54:15Z
- :type start_time: string
- :param end_time: end time, such as 2023-12-05T09:54:15Z
- :type end_time: string
- :param instances: multiple instance names
- :type instances: list of string
- :param cycle: period time
- :type cycle: int
- :param dimensions: dimensions, such as ["httpMethod:POST___GET,path:apipath","httpMethod:POST,path:apipath1]
- :type dimensions: list of string
- :param statistics: statistics, enum: average, maximum, minimum, sum, sampleCount
- :type statistics: list of string
- :param aggr_data: is aggregation data
- :type aggr_data: bool
- :return
- :rtype baidubce.bce_response.BceResponse
- """
- path = (b'/userId/%s/application/%s/task/%s/metricData' % (compat.convert_to_bytes(user_id),
- compat.convert_to_bytes(app_name),
- compat.convert_to_bytes(task_name)))
- params = {b'startTime': start_time, b'endTime': end_time, b'metricName': metric_name}
- if statistics is not None and len(statistics) > 0:
- params[b'statistics'] = ",".join(statistics)
- if cycle is not None and cycle > 0:
- params[b'cycle'] = cycle
- if aggr_data is not None:
- params[b'aggrData'] = aggr_data
- if instances is not None and len(instances) > 0:
- params[b'instances'] = ",".join(instances)
- if dimensions is not None and len(dimensions) > 0:
- params[b'dimensions'] = ",".join(dimensions)
- return self._send_csm_request(http_methods.GET, path, params=params, body_parser=bcm_handler.parse_json_list)
- def list_alarm_metrics_for_application(self, user_id, app_name, task_name, search_name=None):
- """
- :param user_id:
- :type user_id: string
- :param app_name: application name
- :type app_name: string
- :param task_name: task name
- :type task_name: string
- :param search_name: metric name
- :type search_name: string
- :return
- :rtype baidubce.bce_response.BceResponse
- """
- path = (b'/userId/%s/application/%s/%s/alarm/metrics' % (compat.convert_to_bytes(user_id),
- compat.convert_to_bytes(app_name),
- compat.convert_to_bytes(task_name)))
- params = {}
- if search_name is None:
- params[b'searchName'] = search_name
- return self._send_csm_request(http_methods.GET, path, params=params, body_parser=bcm_handler.parse_json_list)
- def get_alarm_policy_for_application(self, user_id, alarm_name, app_name):
- """
- :param user_id:
- :type user_id: string
- :param app_name: application name
- :type app_name: string
- :param alarm_name: alarm name
- :type alarm_name: string
- :return
- :rtype baidubce.bce_response.BceResponse
- """
- path = (b'/userId/%s/application/alarm/%s/config' % (compat.convert_to_bytes(user_id),
- compat.convert_to_bytes(alarm_name)))
- params = {b'appName': app_name}
- return self._send_csm_request(http_methods.GET, path, params=params)
- def delete_alarm_policy_for_application(self, user_id, alarm_name, app_name):
- """
- :param user_id:
- :type user_id: string
- :param app_name: application name
- :type app_name: string
- :param alarm_name: alarm name
- :type alarm_name: string
- :return
- :rtype baidubce.bce_response.BceResponse
- """
- path = (b'/userId/%s/application/alarm/config' % compat.convert_to_bytes(user_id))
- body = {
- 'appName': app_name,
- "alarmName": alarm_name
- }
- return self._send_csm_request(http_methods.DELETE, path, body=json.dumps(body))
- @required(page_no=int, page_size=int)
- def list_alarm_policy_for_application(self, user_id, page_no, page_size=None, app_name=None, alarm_name=None,
- action_enabled=None, src_type=None, task_name=None):
- """
- :param user_id:
- :type user_id: string
- :param page_no: page number
- :type page_no: int
- :param app_name: application name
- :type app_name: string
- :param alarm_name: alarm name
- :type alarm_name: string
- :param action_enabled: is action enabled
- :type action_enabled: bool
- :param src_type: task type, enum: PROC,PORT,LOG,SCR
- :type src_type: string
- :param task_name: task name
- :type task_name: string
- :param page_size: page size
- :type page_size: int
- :return
- :rtype baidubce.bce_response.BceResponse
- """
- path = (b'/userId/%s/application/alarm/config/list' % compat.convert_to_bytes(user_id))
- params = {
- b'pageNo': page_no,
- b'pageSize': page_size,
- b'appName': app_name,
- b'alarmName': alarm_name,
- b'actionEnabled': action_enabled,
- b'srcType': src_type,
- b'taskName': task_name,
- }
- return self._send_csm_request(http_methods.GET, path, params=params)
- @required(rules=list)
- def create_alarm_policy_for_application(self, user_id, alarm_description, alarm_name, app_name,
- monitor_object_type, monitor_object, src_name, src_type, type, level,
- rules, action_enabled=True, incident_actions=None, resume_actions=None,
- insufficient_actions=None, insufficient_cycle=None, repeat_alarm_cycle=0,
- max_repeat_count=0):
- """
- :param user_id:
- :type user_id: string
- :param alarm_description: alarm policy comment
- :type alarm_description: string
- :param alarm_name: unique alarm name in user_id
- :type alarm_name: string
- :param app_name: application name
- :type app_name: string
- :param monitor_object_type: monitor object type, enum: APP, SERVICE
- :type monitor_object_type: string
- :param monitor_object: application monitor object
- :type monitor_object: bcm_model.ApplicationMonitorObject
- :param src_name: task name
- :type src_name: string
- :param src_type: task type, enum: PROC,PORT,LOG,SCR
- :type src_type: string
- :param type: alarm type
- :type type: string
- :param level: alarm level
- :type level: string
- :param rules: list of application alarm rules
- :type rules: list of ApplicationAlarmRule
- :param action_enabled: is alarm action enabled
- :type action_enabled: bool
- :param incident_actions: The action to be taken in the alarm state
- :type incident_actions: list of string
- :param resume_actions: The action to be taken in the alarm resume
- :type resume_actions: list of string
- :param insufficient_actions:
- :type insufficient_actions: list of string
- :param insufficient_cycle: insufficient cycle
- :type insufficient_cycle: int
- :param repeat_alarm_cycle: repeat alarm_cycle
- :type repeat_alarm_cycle: int
- :param max_repeat_count: max repeat count
- :type max_repeat_count: int
- :return
- :rtype baidubce.bce_response.BceResponse
- """
- path = (b'/userId/%s/application/alarm/config/create' % compat.convert_to_bytes(user_id))
- body = {
- "userId": user_id,
- "alarmDescription": alarm_description,
- "appName": app_name,
- "alarmName": alarm_name,
- "monitorObjectType": monitor_object_type,
- "monitorObject": monitor_object,
- "srcName": src_name,
- "srcType": src_type,
- "type": type,
- "level": level,
- "actionEnabled": action_enabled,
- "incidentActions": incident_actions,
- "resumeActions": resume_actions,
- "insufficientActions": insufficient_actions,
- "insufficientCycle": insufficient_cycle,
- "repeatAlarmCycle": repeat_alarm_cycle,
- "maxRepeatCount": max_repeat_count,
- "rules": rules
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
- @required(rules=list)
- def update_alarm_policy_for_application(self, user_id, alarm_description, alarm_name, app_name,
- monitor_object_type, monitor_object, src_name, src_type, type, level,
- rules, action_enabled=True, incident_actions=None, resume_actions=None,
- insufficient_actions=None, insufficient_cycle=None, repeat_alarm_cycle=0,
- max_repeat_count=0):
- """
- :param user_id:
- :type user_id: string
- :param alarm_description: alarm policy comment
- :type alarm_description: string
- :param alarm_name: unique alarm name in user_id
- :type alarm_name: string
- :param app_name: application name
- :type app_name: string
- :param monitor_object_type: monitor object type, enum: APP, SERVICE
- :type monitor_object_type: string
- :param monitor_object: application monitor object
- :type monitor_object: bcm_model.ApplicationMonitorObject
- :param src_name: task name
- :type src_name: string
- :param src_type: task type, enum: PROC,PORT,LOG,SCR
- :type src_type: string
- :param type: alarm type
- :type type: string
- :param level: alarm level
- :type level: string
- :param rules: list of application alarm rules
- :type rules: list of ApplicationAlarmRule
- :param action_enabled: is alarm action enabled
- :type action_enabled: bool
- :param incident_actions: The action to be taken in the alarm state
- :type incident_actions: list of string
- :param resume_actions: The action to be taken in the alarm resume
- :type resume_actions: list of string
- :param insufficient_actions:
- :type insufficient_actions: list of string
- :param insufficient_cycle: insufficient cycle
- :type insufficient_cycle: int
- :param repeat_alarm_cycle: repeat alarm_cycle
- :type repeat_alarm_cycle: int
- :param max_repeat_count: max repeat count
- :type max_repeat_count: int
- :return
- :rtype baidubce.bce_response.BceResponse
- """
- path = (b'/userId/%s/application/alarm/config/update' % compat.convert_to_bytes(user_id))
- body = {
- "userId": user_id,
- "alarmDescription": alarm_description,
- "appName": app_name,
- "alarmName": alarm_name,
- "monitorObjectType": monitor_object_type,
- "monitorObject": monitor_object,
- "srcName": src_name,
- "srcType": src_type,
- "type": type,
- "level": level,
- "actionEnabled": action_enabled,
- "incidentActions": incident_actions,
- "resumeActions": resume_actions,
- "insufficientActions": insufficient_actions,
- "insufficientCycle": insufficient_cycle,
- "repeatAlarmCycle": repeat_alarm_cycle,
- "maxRepeatCount": max_repeat_count,
- "rules": rules
- }
- return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body))
- def create_dashboard(self, user_id=None, title=None, configure=None, dashboard_type=None, config=None):
- """
- Create a dashboard
- :param user_id:
- Master account ID
- :type user_id: string
- :param title:
- Title of the dashboard
- :type title: string
- :param configure:
- Configure the dashboard
- :type configure:string
- :param dashboard_type:
- Dashboard type
- :type dashboard_type:string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- body = {
- "userId": user_id,
- "title": title,
- "configure": configure,
- "type": dashboard_type
- }
- user_id = compat.convert_to_bytes(user_id)
- path = b'/dashboard/products/%s/dashboards' % user_id
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def get_dashboard(self, user_id=None, dashboard_name=None, config=None):
- """
- Create a dashboard
- :param user_id:
- Master account ID
- :type user_id: string
- :param dashboard_name:
- Dashboard name
- :type dashboard_name:string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(dashboard_name) <= 0:
- raise ValueError('dashboard_name should not be none or empty string')
- user_id = compat.convert_to_bytes(user_id)
- dashboard_name = compat.convert_to_bytes(dashboard_name)
- path = b'/dashboard/products/%s/dashboards/%s' % (user_id, dashboard_name)
- return self._send_csm_request(http_methods.GET, path, config=config)
- def update_dashboard(self, user_id=None, title=None, configure=None,
- dashboard_type=None, dashboard_name=None, config=None):
- """
- Create a dashboard
- :param user_id:
- Master account ID
- :type user_id: string
- :param title:
- Title of the dashboard
- :type title: string
- :param configure:
- Configure the dashboard
- :type configure:string
- :param dashboard_type:
- Dashboard type
- :type dashboard_type:string
- :param dashboard_name:
- Dashboard name
- :type dashboard_name:string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(dashboard_name) <= 0:
- raise ValueError('dashboard_name should not be none or empty string')
- body = {
- "userId": user_id,
- "title": title,
- "configure": configure,
- "type": dashboard_type
- }
- user_id = compat.convert_to_bytes(user_id)
- dashboard_name = compat.convert_to_bytes(dashboard_name)
- path = b'/dashboard/products/%s/dashboards/%s' % (user_id, dashboard_name)
- return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
- def delete_dashboard(self, user_id=None, dashboard_name=None, config=None):
- """
- Create a dashboard
- :param user_id:
- Master account ID
- :type user_id: string
- :param dashboard_name:
- Dashboard name
- :type dashboard_name:string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(dashboard_name) <= 0:
- raise ValueError('dashboard_name should not be none or empty string')
- user_id = compat.convert_to_bytes(user_id)
- dashboard_name = compat.convert_to_bytes(dashboard_name)
- path = b'/dashboard/products/%s/dashboards/%s' % (user_id, dashboard_name)
- return self._send_csm_request(http_methods.DELETE, path, config=config)
- def duplicate_dashboard(self, user_id=None, dashboard_name=None, config=None):
- """
- Create a dashboard
- :param user_id:
- Master account ID
- :type user_id: string
- :param dashboard_name:
- Dashboard name
- :type dashboard_name:string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(dashboard_name) <= 0:
- raise ValueError('dashboard_name should not be none or empty string')
- body = {
- }
- user_id = compat.convert_to_bytes(user_id)
- dashboard_name = compat.convert_to_bytes(dashboard_name)
- path = b'/dashboard/products/%s/dashboards/%s/duplicate' % (user_id, dashboard_name)
- return self._send_csm_request(http_methods.POST, path, json.dumps(body), config=config)
- def create_dashboard_widget(self, user_id=None, dashboard_name=None, config=None):
- """
- Create a dashboard
- :param user_id:
- Master account ID
- :type user_id: string
- :param dashboard_name:
- Dashboard name
- :type dashboard_name:string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(dashboard_name) <= 0:
- raise ValueError('dashboard_name should not be none or empty string')
- body = {
- }
- user_id = compat.convert_to_bytes(user_id)
- dashboard_name = compat.convert_to_bytes(dashboard_name)
- path = b'/dashboard/products/%s/dashboards/%s/widgets' % (user_id, dashboard_name)
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def get_dashboard_widget(self, user_id=None, dashboard_name=None, widget_name=None, config=None):
- """
- Create a dashboard
- :param user_id:
- Master account ID
- :type user_id: string
- :param dashboard_name:
- Dashboard name
- :type dashboard_name:string
- :param widget_name:
- Widget name
- :type widget_name:string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(dashboard_name) <= 0:
- raise ValueError('dashboard_name should not be none or empty string')
- if len(widget_name) <= 0:
- raise ValueError('widget_name should be none or empty string')
- user_id = compat.convert_to_bytes(user_id)
- dashboard_name = compat.convert_to_bytes(dashboard_name)
- widget_name = compat.convert_to_bytes(widget_name)
- path = b'/dashboard/products/%s/dashboards/%s/widgets/%s' % (user_id, dashboard_name, widget_name)
- return self._send_csm_request(http_methods.GET, path, config=config)
- def delete_dashboard_widget(self, user_id=None, dashboard_name=None, widget_name=None, config=None):
- """
- Create a dashboard
- :param user_id:
- Master account ID
- :type user_id: string
- :param dashboard_name:
- Dashboard name
- :type dashboard_name:string
- :param widget_name:
- Widget name
- :type widget_name:string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(dashboard_name) <= 0:
- raise ValueError('dashboard_name should not be none or empty string')
- if len(widget_name) <= 0:
- raise ValueError('widget_name should be none or empty string')
- user_id = compat.convert_to_bytes(user_id)
- dashboard_name = compat.convert_to_bytes(dashboard_name)
- widget_name = compat.convert_to_bytes(widget_name)
- path = b'/dashboard/products/%s/dashboards/%s/widgets/%s' % (user_id, dashboard_name, widget_name)
- return self._send_csm_request(http_methods.DELETE, path, config=config)
- def duplicate_dashboard_widget(self, user_id=None, dashboard_name=None, widget_name=None, config=None):
- """
- Create a dashboard
- :param user_id:
- Master account ID
- :type user_id: string
- :param dashboard_name:
- Dashboard name
- :type dashboard_name:string
- :param widget_name:
- Widget name
- :type widget_name:string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(dashboard_name) <= 0:
- raise ValueError('dashboard_name should not be none or empty string')
- if len(widget_name) <= 0:
- raise ValueError('widget_name should be none or empty string')
- body = {
- }
- user_id = compat.convert_to_bytes(user_id)
- dashboard_name = compat.convert_to_bytes(dashboard_name)
- widget_name = compat.convert_to_bytes(widget_name)
- path = (b'/dashboard/products/%s/dashboards/%s/widgets/%s/duplicate' %
- (user_id, dashboard_name, widget_name))
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def update_dashboard_widget(self, user_id=None, dashboard_name=None, widget_name=None,
- widget_type=None, title=None, configure=None, config=None):
- """
- Create a dashboard
- :param user_id:
- Master account ID
- :type user_id: string
- :param dashboard_name:
- Dashboard name
- :type dashboard_name:string
- :param widget_name:
- Widget name
- :type widget_name:string
- :param widget_type:
- Widget type
- :type widget_type:string
- :param configure:
- Widget configure
- :type configure:object
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(dashboard_name) <= 0:
- raise ValueError('dashboard_name should not be none or empty string')
- if len(widget_name) <= 0:
- raise ValueError('widget_name should be none or empty string')
- body = {
- "title": title,
- "type": widget_type,
- "configure": configure
- }
- user_id = compat.convert_to_bytes(user_id)
- dashboard_name = compat.convert_to_bytes(dashboard_name)
- widget_name = compat.convert_to_bytes(widget_name)
- path = b'/dashboard/products/%s/dashboards/%s/widgets/%s' % (user_id, dashboard_name, widget_name)
- return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
- def get_dashboard_report_data(self, data=None, time=None, config=None):
- """
- Get dashboard report data
- :param data:
- Query data
- :type data: object
- :param time:
- Query data time
- :type time: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- body = {
- "data": data,
- "time": time
- }
- path = b'/dashboard/metric/report'
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def get_dashboard_trend_data(self, data=None, time=None, config=None):
- """
- Get dashboard report data
- :param data:
- Query data
- :type data: object
- :param time:
- Query data time
- :type time: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- body = {
- "data": data,
- "time": time
- }
- path = b'/dashboard/metric/trend'
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def get_dashboard_gauge_chart_data(self, data=None, time=None, config=None):
- """
- Get dashboard report data
- :param data:
- Query data
- :type data: object
- :param time:
- Query data time
- :type time: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- body = {
- "data": data,
- "time": time
- }
- path = b'/dashboard/metric/gaugechart'
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def get_dashboard_billboard_data(self, data=None, time=None, config=None):
- """
- Get dashboard report data
- :param data:
- Query data
- :type data: object
- :param time:
- Query data time
- :type time: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- body = {
- "data": data,
- "time": time
- }
- path = b'/dashboard/metric/billboard'
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def get_dashboard_trend_senior_data(self, data=None, time=None, config=None):
- """
- Get dashboard report data
- :param data:
- Query data
- :type data: object
- :param time:
- Query data time
- :type time: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- body = {
- "data": data,
- "time": time
- }
- path = b'/dashboard/metric/trend/senior'
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def get_dashboard_dimensions(self, user_id, metric_name, region, service, show_id,
- dimensions=None, config=None):
- """
- Get dashboard dimensions
- :param user_id:
- Master account ID
- :type user_id: string
- :param dimensions:
- dashboard dimensions
- :type dimensions: string
- :param metric_name:
- dashboard metric_name
- :type metric_name: string
- :param region:
- dashboard dimensions region
- :type region: string
- :param service:
- cloud service
- :type service:
- :param show_id:
- cloud resourceId
- :type show_id:
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(metric_name) <= 0:
- raise ValueError('metric_name should not be none or empty string')
- if len(region) <= 0:
- raise ValueError('region should not be none or empty string')
- if len(service) <= 0:
- raise ValueError('service should not be none or empty string')
- if len(show_id) <= 0:
- raise ValueError('show_id should not be none or empty string')
- params = {
- b'dimensions': dimensions,
- b'userId': user_id,
- b'metricName': metric_name,
- b'region': region,
- b'service': service,
- b'showId': show_id,
- }
- user_id = compat.convert_to_bytes(user_id)
- service = compat.convert_to_bytes(service)
- region = compat.convert_to_bytes(region)
- path = b'/userId/%s/services/%s/region/%s/metric/dimensions' % (user_id, service, region)
- return self._send_csm_request(http_methods.GET, path, params=params, config=config)
- def create_application_data(self, name, type, user_id, alias=None, description=None, config=None):
- """
- create application data
- :param name:
- :param type:
- :param user_id:
- :param alias:
- :param description:
- :param config:
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError("user_id should not be null")
- if len(type) <= 0:
- raise ValueError("type should not be null")
- if len(name) <= 0:
- raise ValueError("name should not be null")
- req = {
- "name": name,
- "type": type,
- "userId": user_id,
- }
- if alias is not None:
- req["alias"] = alias
- if description is not None:
- req["description"] = description
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/application' % user_id
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(req), config=config)
- def get_application_data_list(self, user_id, page_no=None, page_size=None, search_name=None, config=None):
- """
- get_application_data_list
- :param user_id:
- :param page_no:
- :param page_size:
- :param search_name:
- :param config:
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError("user_id should not be null")
- if page_no is None:
- page_no = 1
- if page_size is None:
- page_size = 10
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/application' % user_id
- params = {
- b'pageSize': page_size,
- b'pageNo': page_no,
- }
- if search_name is not None:
- params[b'searchName'] = search_name
- return self._send_request(http_methods.GET, path, params=params, config=config)
- def update_application_data(self, user_id, id, name, type, alias=None, description=None, config=None):
- """
- update_application_data
- :param user_id:
- :param id:
- :param name:
- :param type:
- :param alias:
- :param description:
- :param config:
- :return:
- """
- if len(user_id) <= 0:
- raise ValueError("user_id should not be null")
- if len(type) <= 0:
- raise ValueError("type should not be null")
- if len(name) <= 0:
- raise ValueError("name should not be null")
- if len(id) <= 0:
- raise ValueError("id should not be null")
- req = {
- "userId": user_id,
- "id": id,
- "name": name,
- "type": type
- }
- if alias is not None:
- req["alias"] = alias
- if description is not None:
- req["description"] = description
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/application' % user_id
- return self._send_csm_request(http_methods.PUT, path, body=json.dumps(req), config=config)
- def delete_application_data(self, user_id, name, config=None):
- """
- delete_application_data
- :param user_id:
- :param name:
- :param config:
- :return:
- """
- if len(user_id) <= 0:
- raise ValueError("user_id should not be null")
- if len(name) <= 0:
- raise ValueError("name should null be null")
- req = {
- "name": name
- }
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/application' % user_id
- return self._send_csm_request(http_methods.DELETE, path, body=json.dumps(req), config=config)
- def get_application_instance_list(self, user_id, region, app_name, search_name, page_no=None, page_size=None,
- search_value=None, config=None):
- """
- get_application_instance_list
- :param user_id:
- :param region:
- :param app_name:
- :param search_name:
- :param page_no:
- :param page_size:
- :param search_value:
- :param config:
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError("user_id should not be null")
- if len(region) <= 0:
- raise ValueError("region should not be null")
- if len(app_name) <= 0:
- raise ValueError("app_name should not be null")
- if page_no is None:
- page_no = 1
- if page_size is None:
- page_size = 10
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/instances/all' % user_id
- req = {
- "appName": app_name,
- "region": region,
- "pageNo": page_no,
- "pageSize": page_size,
- "searchName": search_name
- }
- if search_value is not None:
- req["searchValue"] = search_value
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(req), config=config)
- @required(user_id=value_type,
- app_name=value_type,
- host_list=list)
- def create_application_instance(self, user_id, app_name, host_list, config=None):
- """
- create_application_instance
- :param user_id:
- :param app_name:
- :param host_list:
- :param config:
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError("user_id should not be null")
- if len(app_name) <= 0:
- raise ValueError("app_name should not be null")
- if len(host_list) <= 0:
- raise ValueError("host_list should not be null")
- host_list_json = []
- for host in host_list:
- host_list_json.append(host)
- req = {
- "appName": app_name,
- "userId": user_id,
- "hostList": host_list_json
- }
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/application/instance/bind' % user_id
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(req), config=config)
- def get_application_instance_created_list(self, user_id, app_name, region=None, config=None):
- """
- get_application_instance_created_list
- :param user_id:
- :param app_name:
- :param region:
- :param config:
- :return:
- """
- if len(user_id) <= 0:
- raise ValueError("user_id should not be null")
- if len(app_name) <= 0:
- raise ValueError("app_name should not be null")
- user_id = compat.convert_to_bytes(user_id)
- app_name = compat.convert_to_bytes(app_name)
- path = b'/userId/%s/application/%s/instance/list' % (user_id, app_name)
- params = None
- if region is not None:
- params = {
- 'region': region
- }
- return self._send_csm_request(http_methods.GET, path, params=params, config=config)
- def delete_application_instance(self, user_id, app_name, id, config=None):
- """
- delete_application_instance
- :param user_id:
- :param app_name:
- :param id:
- :param config:
- :return:
- """
- if len(user_id) <= 0:
- raise ValueError("user_id should not be null")
- if len(app_name) <= 0:
- raise ValueError("app_name should not be null")
- if len(id) <= 0:
- raise ValueError("id should not be null")
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/application/instance' % user_id
- req = {
- "id": id,
- "appName": app_name
- }
- return self._send_csm_request(http_methods.DELETE, path, body=json.dumps(req), config=config)
- @required(user_id=value_type, app_name=value_type, alias_name=value_type, type=int,
- target=value_type, cycle=int, description=value_type, log_example=value_type,
- match_rule=value_type, rate=int, extract_result=list, metrics=list)
- def create_application_instance_task(self, user_id, app_name, alias_name, type, target,
- cycle=None, description=None, log_example=None, match_rule=None, rate=None,
- extract_result=None, metrics=None, config=None):
- """
- create_application_instance_task
- :param user_id:
- :param app_name:
- :param alias_name:
- :param type:
- :param target:
- :param cycle:
- :param description:
- :param log_example:
- :param match_rule:
- :param rate:
- :param extract_result:
- :param metrics:
- :param config:
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError("user_id should not be null")
- if len(app_name) <= 0:
- raise ValueError("app_name should not be null")
- if type is None:
- raise ValueError("type should not be null")
- if len(alias_name) <= 0:
- raise ValueError("alias_name should not be null")
- if len(target) <= 0:
- raise ValueError("target should not be null")
- if cycle is None:
- cycle = 60
- req = {
- "appName": app_name,
- "type": str(type),
- "aliasName": alias_name,
- "target": target,
- "cycle": str(cycle)
- }
- if description is not None:
- req["description"] = description
- if str(type) == "2":
- if log_example is None:
- raise ValueError("log_example should not be null")
- if match_rule is None:
- raise ValueError("match_rule should not be null")
- if rate is None:
- raise ValueError("rate should not be null")
- if extract_result is None:
- raise ValueError("extract_result should not be null")
- if metrics is None:
- raise ValueError("metrics should not be null")
- req["logExample"] = log_example
- req["matchRule"] = match_rule
- req["rate"] = rate
- extract_result_json = []
- for result in extract_result:
- extract_result_json.append(result)
- req["extractResult"] = extract_result_json
- metrics_json = []
- for metric in metrics:
- metrics_json.append(metric)
- req["metrics"] = metrics_json
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/application/task/create' % user_id
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(req), config=config)
- def get_application_monitor_task_detail(self, user_id, app_name, task_name, config=None):
- """
- get_application_monitor_task_detail
- :param user_id:
- :param app_name:
- :param task_name:
- :param config:
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError("user_id should not be null")
- if len(app_name) <= 0:
- raise ValueError("app_name should not be null")
- if len(task_name) <= 0:
- raise ValueError("task_name should not be null")
- user_id = compat.convert_to_bytes(user_id)
- app_name = compat.convert_to_bytes(app_name)
- task_name = compat.convert_to_bytes(task_name)
- path = b'/userId/%s/application/%s/task/%s' % (user_id, app_name, task_name)
- return self._send_csm_request(http_methods.GET, path, config=config)
- def get_application_monitor_task_list(self, user_id, app_name, type=None, config=None):
- """
- get_application_monitor_task_list
- :param user_id:
- :param app_name:
- :param type:
- :param config:
- :return:
- """
- if len(user_id) <= 0:
- raise ValueError("user_id should not be null")
- if len(app_name) <= 0:
- raise ValueError("app_name should not be null")
- user_id = compat.convert_to_bytes(user_id)
- app_name = compat.convert_to_bytes(app_name)
- path = b'/userId/%s/application/%s/task/list' % (user_id, app_name)
- params = None
- if type is not None:
- params = {
- 'type': type
- }
- return self._send_csm_request(http_methods.GET, path, params=params, config=config,
- body_parser=bcm_handler.parse_json_list)
- @required(user_id=value_type, app_name=value_type, name=value_type, alias_name=value_type, type=int,
- target=value_type, cycle=int, description=value_type, log_example=value_type,
- match_rule=value_type, rate=int, extract_result=list, metrics=list)
- def update_application_monitor_task(self, user_id, app_name, alias_name, name, type, target,
- cycle=None, description=None, log_example=None, match_rule=None, rate=None,
- extract_result=None, metrics=None, config=None):
- """
- update application monitor task
- :param user_id:
- :param app_name:
- :param alias_name:
- :param name:
- :param type:
- :param target:
- :param cycle:
- :param description:
- :param log_example:
- :param match_rule:
- :param rate:
- :param extract_result:
- :param metrics:
- :param config:
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError("user_id should not be null")
- if len(app_name) <= 0:
- raise ValueError("app_name should not be null")
- if len(name) <= 0:
- raise ValueError("name should not be null")
- if type is None:
- raise ValueError("type should not be null")
- if len(alias_name) <= 0:
- raise ValueError("alias_name should not be null")
- if len(target) <= 0:
- raise ValueError("target should not be null")
- req = {
- "appName": app_name,
- "name": name,
- "type": str(type),
- "aliasName": alias_name,
- "target": target,
- }
- if cycle is not None:
- req["cycle"] = cycle
- if description is not None:
- req["description"] = description
- if str(type) == "2":
- if log_example is None:
- raise ValueError("log_example should not be null")
- if match_rule is None:
- raise ValueError("match_rule should not be null")
- if rate is None:
- raise ValueError("rate should not be null")
- if extract_result is None:
- raise ValueError("extract_result should not be null")
- if metrics is None:
- raise ValueError("metrics should not be null")
- req["logExample"] = log_example
- req["matchRule"] = match_rule
- req["rate"] = rate
- extract_result_json = []
- for result in extract_result:
- extract_result_json.append(result)
- req["extractResult"] = extract_result_json
- metrics_json = []
- for metric in metrics:
- metrics_json.append(metric)
- req["metrics"] = metrics_json
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/application/task/update' % user_id
- return self._send_csm_request(http_methods.PUT, path, body=json.dumps(req), config=config)
- def delete_application_monitor_task(self, user_id, name, app_name, config=None):
- """
- delete_application_monitor_task
- :param user_id:
- :param name:
- :param app_name:
- :param config:
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError("user_id should not be null")
- if len(app_name) <= 0:
- raise ValueError("app_name should not be null")
- if len(name) <= 0:
- raise ValueError("name should not be null")
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/application/task/delete' % user_id
- req = {
- "name": name,
- "appName": app_name
- }
- return self._send_csm_request(http_methods.DELETE, path, body=json.dumps(req), config=config)
- def create_application_dimension_table(self, user_id, app_name, table_name, map_content_json, config=None):
- """
- create_application_dimension_table
- :param user_id:
- :param app_name:
- :param table_name:
- :param map_content_json:
- :param config:
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError("user_id should not be null")
- if len(app_name) <= 0:
- raise ValueError("app_name should not be null")
- if len(table_name) <= 0:
- raise ValueError("table_name should not be null")
- if len(map_content_json) <= 0:
- raise ValueError("map_content_json should not be null")
- req = {
- "userId": user_id,
- "appName": app_name,
- "tableName": table_name,
- "mapContentJson": map_content_json
- }
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/application/dimensionMap/create' % user_id
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(req), config=config)
- def get_application_dimension_table_list(self, user_id, app_name, search_name=None, config=None):
- """
- get_application_dimension_table_list
- :param user_id:
- :param app_name:
- :param search_name:
- :param config:
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError("user_id should not be null")
- if len(app_name) <= 0:
- raise ValueError("app_name should not be null")
- user_id = compat.convert_to_bytes(user_id)
- app_name = compat.convert_to_bytes(app_name)
- path = b'/userId/%s/application/%s/dimensionMap/list' % (user_id, app_name)
- params = None
- if search_name is not None:
- params = {
- 'searchName': search_name
- }
- return self._send_csm_request(http_methods.GET, path, params=params, config=config)
- def update_application_dimension_table(self, user_id, app_name, table_name, map_content_json, config=None):
- """
- update_application_dimension_table
- :param user_id:
- :param app_name:
- :param table_name:
- :param map_content_json:
- :param config:
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError("user_id should not be null")
- if len(app_name) <= 0:
- raise ValueError("app_name should not be null")
- if len(table_name) <= 0:
- raise ValueError("table_name should not be null")
- if len(map_content_json) <= 0:
- raise ValueError("map_content_json should not be null")
- req = {
- "userId": user_id,
- "appName": app_name,
- "tableName": table_name,
- "mapContentJson": map_content_json
- }
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/application/dimensionMap/update' % user_id
- return self._send_csm_request(http_methods.PUT, path, body=json.dumps(req), config=config)
- def delete_application_dimension_table(self, user_id, app_name, table_name, config=None):
- """
- delete_application_dimension_table
- :param user_id:
- :param app_name:
- :param table_name:
- :param config:
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError("user_id should not be null")
- if len(app_name) <= 0:
- raise ValueError("app_name should not be null")
- if len(table_name) <= 0:
- raise ValueError("table_name should not be null")
- req = {
- "userId": user_id,
- "appName": app_name,
- "tableName": table_name
- }
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/application/dimensionMap/delete' % user_id
- return self._send_csm_request(http_methods.DELETE, path, body=json.dumps(req), config=config)
- @required(page_no=int, page_size=int, account_id=str, start_time=str, end_time=str)
- def get_cloud_event_data(self, page_no=1, page_size=10, start_time=None, end_time=None, account_id=None,
- ascending=None, scope=None, region=None, event_level=None, event_name=None,
- event_alias=None, resource_type=None, resource_id=None, event_id=None):
- """
- :param page_no: page number
- :type page_no: int
- :param page_size: page size
- :type page_size: int
- :param start_time: start time, such as 2023-12-05T09:54:15Z
- :type start_time: string
- :param end_time: end time, such as 2023-12-05T09:54:15Z
- :type end_time: string
- :param account_id: account id
- :type account_id: string
- :param ascending: ascending
- :type ascending: bool
- :param scope: scope
- :type scope: string
- :param region: region
- :type region: string
- :param event_level: event level
- :type event_level: None or ENUM {'NOTICE', 'WARNING', 'MAJOR', 'CRITICAL'}
- :param event_name: event name
- :type event_name: string
- :param event_alias: event alias
- :type event_alias: string
- :param resource_type: resource type
- :type resource_type: string
- :param resource_id: resource id
- :type resource_id: string
- :param event_id: event id
- :type event_id: string
- :return
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/bce-event/list'
- params = {
- b'pageNo': page_no,
- b'pageSize': page_size,
- b'startTime': start_time,
- b'endTime': end_time,
- b'accountId': account_id,
- b'ascending': ascending,
- b'scope': scope,
- b'region': region,
- b'eventLevel': event_level,
- b'eventName': event_name,
- b'eventAlias': event_alias,
- b'resourceType': resource_type,
- b'resourceId': resource_id,
- b'eventId': event_id,
- }
- return self._send_event_request(http_methods.GET, path, params=params)
- @required(page_no=int, page_size=int, account_id=str, start_time=str, end_time=str)
- def get_platform_event_data(self, page_no=1, page_size=10, start_time=None, end_time=None, account_id=None,
- ascending=None, scope=None, region=None, event_level=None, event_name=None,
- event_alias=None, event_id=None):
- """
- :param page_no: page number
- :type page_no: int
- :param page_size: page size
- :type page_size: int
- :param start_time: start time, such as 2023-12-05T09:54:15Z
- :type start_time: string
- :param end_time: end time, such as 2023-12-05T09:54:15Z
- :type end_time: string
- :param account_id: account id
- :type account_id: string
- :param ascending: ascending
- :type ascending: bool
- :param scope: scope
- :type scope: string
- :param region: region
- :type region: string
- :param event_level: event level
- :type event_level: None or ENUM {'NOTICE', 'WARNING', 'MAJOR', 'CRITICAL'}
- :param event_name: event name
- :type event_name: string
- :param event_alias: event alias
- :type event_alias: string
- :param event_id: event id
- :type event_id: string
- :return
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/platform-event/list'
- params = {
- b'pageNo': page_no,
- b'pageSize': page_size,
- b'startTime': start_time,
- b'endTime': end_time,
- b'accountId': account_id,
- b'ascending': ascending,
- b'scope': scope,
- b'region': region,
- b'eventLevel': event_level,
- b'eventName': event_name,
- b'eventAlias': event_alias,
- b'eventId': event_id,
- }
- return self._send_event_request(http_methods.GET, path, params=params)
- @required(account_id=str, service_name=str, name=str, block_status=str, incident_actions=list)
- def create_event_policy(self, account_id, service_name, name, block_status, event_filter,
- resource, incident_actions):
- """
- :param account_id: account id
- :type account_id: string
- :param service_name: service name
- :type service_name: string
- :param name: event policy name
- :type name: string
- :param block_status: block status, enum: NORMAL, BLOCKED
- :type block_status: string
- :param event_filter: event filter
- :type event_filter: EventFilter
- :param resource: resource filter
- :type resource: EventResourceFilter
- :param incident_actions: incident actions
- :type incident_actions: list of string
- """
- if event_filter is None:
- raise ValueError('event_filter should not be none')
- if resource is None:
- raise ValueError('resource should not be none')
- path = b'/accounts/%s/services/%s/alarm-policies' % (compat.convert_to_bytes(account_id),
- compat.convert_to_bytes(service_name))
- body = {
- "account_id": account_id,
- "service_name": service_name,
- "name": name,
- "blockStatus": block_status,
- "eventFilter": event_filter,
- "resource": resource,
- "incidentActions": incident_actions
- }
- return self._send_event_request(http_methods.POST, path, body=json.dumps(body))
- @required(user_id=str, region=str, service_name=str, type_name=str, name=str)
- def create_instance_group(self, user_id, region, service_name, type_name, name, resource_id_list):
- """
- :param user_id: user id
- :type user_id: string
- :param region: region
- :type region: string
- :param service_name: service name
- :type service_name: string
- :param type_name: type name
- :type type_name: string
- :param name: instance group name
- :type name: string
- :param resource_id_list: resource id list
- :type resource_id_list: list of MonitorResource
- """
- path = b'/userId/%s/instance-group' % compat.convert_to_bytes(user_id)
- body = {
- "userId": user_id,
- "region": region,
- "serviceName": service_name,
- "typeName": type_name,
- "name": name,
- "resourceIdList": resource_id_list
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
- @required(user_id=str, ig_id=str, region=str, service_name=str, type_name=str, name=str)
- def update_instance_group(self, ig_id, user_id, region, service_name, type_name, name):
- """
- :param ig_id: instance group id
- :type ig_id: string
- :param user_id: user id
- :type user_id: string
- :param region: region
- :type region: string
- :param service_name: service name
- :type service_name: string
- :param type_name: type name
- :type type_name: string
- :param name: instance group name
- :type name: string
- """
- path = b'/userId/%s/instance-group' % compat.convert_to_bytes(user_id)
- body = {
- "id": ig_id,
- "userId": user_id,
- "region": region,
- "serviceName": service_name,
- "typeName": type_name,
- "name": name,
- }
- return self._send_csm_request(http_methods.PATCH, path, body=json.dumps(body))
- @required(user_id=str, ig_id=str)
- def delete_instance_group(self, user_id, ig_id):
- """
- :param user_id: user id
- :type user_id: string
- :param ig_id: instance group id
- :type ig_id: string
- """
- path = b'/userId/%s/instance-group/%s' % (compat.convert_to_bytes(user_id), compat.convert_to_bytes(ig_id))
- return self._send_csm_request(http_methods.DELETE, path)
- @required(user_id=str, ig_id=str)
- def get_instance_group(self, user_id, ig_id):
- """
- :param user_id: user id
- :type user_id: string
- :param ig_id: instance group id
- :type ig_id: string
- """
- path = b'/userId/%s/instance-group/%s' % (compat.convert_to_bytes(user_id), compat.convert_to_bytes(ig_id))
- return self._send_csm_request(http_methods.GET, path)
- @required(user_id=str, page_no=int, page_size=int)
- def list_instance_group(self, user_id, name, service_name, region, type_name, page_no, page_size):
- """
- :param user_id: user id
- :type user_id: string
- :param name: instance group name
- :type name: string
- :param service_name: service name
- :type service_name: string
- :param region: region
- :type region: string
- :param type_name: type name
- :type type_name: string
- :param page_no: page number
- :type page_no: int
- :param page_size: page size
- :type page_size: int
- """
- path = b'/userId/%s/instance-group/list' % compat.convert_to_bytes(user_id)
- params = {
- b"userId": user_id,
- b"name": name,
- b"serviceName": service_name,
- b"region": region,
- b"typeName": type_name,
- b"pageNo": page_no,
- b"pageSize": page_size
- }
- return self._send_csm_request(http_methods.GET, path, params=params)
- @required(user_id=str, ig_id=str, resource_id_list=list)
- def add_ig_instance(self, ig_id, user_id, resource_id_list):
- """
- :param ig_id: instance group id
- :type ig_id: string
- :param user_id: user id
- :type user_id: string
- :param resource_id_list: resource id list
- :type resource_id_list: list of MonitorResource
- """
- path = b'/userId/%s/instance-group/%s/instance/add' % (compat.convert_to_bytes(user_id),
- compat.convert_to_bytes(ig_id))
- body = {
- "id": ig_id,
- "userId": user_id,
- "resourceIdList": resource_id_list
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
- @required(user_id=str, ig_id=str, resource_id_list=list)
- def remove_ig_instance(self, ig_id, user_id, resource_id_list):
- """
- :param ig_id: instance group id
- :type ig_id: string
- :param user_id: user id
- :type user_id: string
- :param resource_id_list: resource id list
- :type resource_id_list: list of MonitorResource
- """
- path = b'/userId/%s/instance-group/%s/instance/remove' % (compat.convert_to_bytes(user_id),
- compat.convert_to_bytes(ig_id))
- body = {
- "id": ig_id,
- "userId": user_id,
- "resourceIdList": resource_id_list
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
- @required(user_id=str, ig_id=str, service_name=str, type_name=str, region=str, view_type=str,
- page_no=int, page_size=int)
- def list_ig_instance(self, user_id, ig_id, service_name, type_name, region, view_type, page_no, page_size):
- """
- :param user_id: user id
- :type user_id: string
- :param ig_id: instance group id
- :type ig_id: string
- :param service_name: service name
- :type service_name: string
- :param type_name: type name
- :type type_name: string
- :param region: region
- :type region: string
- :param view_type: view type, enum: LIST_VIEW, DETAIL_VIEW
- :type view_type: string
- :param page_no: page number
- :type page_no: int
- :param page_size: page size
- :type page_size: int
- """
- path = b'/userId/%s/instance-group/instance/list' % compat.convert_to_bytes(user_id)
- params = {
- b"id": ig_id,
- b"userId": user_id,
- b"serviceName": service_name,
- b"typeName": type_name,
- b"region": region,
- b"viewType": view_type,
- b"pageNo": page_no,
- b"pageSize": page_size
- }
- return self._send_csm_request(http_methods.GET, path, params=params)
- @required(user_id=str, service_name=str, type_name=str, region=str, view_type=str, keyword_type=str, keyword=str,
- page_no=int, page_size=int)
- def list_all_instance(self, user_id, service_name, type_name, region, view_type, keyword_type, keyword,
- page_no, page_size):
- """
- :param user_id: user id
- :type user_id: string
- :param service_name: service name
- :type service_name: string
- :param type_name: type name
- :type type_name: string
- :param region: region
- :type region: string
- :param view_type: view type, enum: LIST_VIEW, DETAIL_VIEW
- :type view_type: string
- :param keyword_type: keyword type, enum: name, id
- :type keyword_type: string
- :param keyword: keyword
- :type keyword: string
- :param page_no: page number
- :type page_no: int
- :param page_size: page size
- :type page_size: int
- """
- path = b'/userId/%s/instance/list' % compat.convert_to_bytes(user_id)
- params = {
- b"userId": user_id,
- b"serviceName": service_name,
- b"typeName": type_name,
- b"region": region,
- b"viewType": view_type,
- b"keywordType": keyword_type,
- b"keyword": keyword,
- b"pageNo": page_no,
- b"pageSize": page_size
- }
- return self._send_csm_request(http_methods.GET, path, params=params)
- @required(user_id=str, ig_id=str, ig_uuid=str, service_name=str, type_name=str, region=str, view_type=str,
- keyword_type=str, keyword=str, page_no=int, page_size=int)
- def list_filter_instance(self, user_id, ig_id, ig_uuid, service_name, type_name, region, view_type,
- keyword_type, keyword, page_no, page_size):
- """
- :param user_id: user id
- :type user_id: string
- :param ig_id: instance group id
- :type ig_id: string
- :param ig_uuid: instance group uuid
- :type ig_uuid: string
- :param service_name: service name
- :type service_name: string
- :param type_name: type name
- :type type_name: string
- :param region: region
- :type region: string
- :param view_type: view type, enum: LIST_VIEW, DETAIL_VIEW
- :type view_type: string
- :param keyword_type: keyword type, enum: name, id
- :type keyword_type: string
- :param keyword: keyword
- :type keyword: string
- :param page_no: page number
- :type page_no: int
- :param page_size: page size
- :type page_size: int
- """
- path = b'/userId/%s/instance/filteredList' % compat.convert_to_bytes(user_id)
- params = {
- b"userId": user_id,
- b"id": ig_id,
- b"uuid": ig_uuid,
- b"serviceName": service_name,
- b"typeName": type_name,
- b"region": region,
- b"viewType": view_type,
- b"keywordType": keyword_type,
- b"keyword": keyword,
- b"pageNo": page_no,
- b"pageSize": page_size
- }
- return self._send_csm_request(http_methods.GET, path, params=params)
- def push_metric_data(self, user_id=None, scope=None, metric_data=None, config=None):
- """
- :param user_id: user_id
- :type user_id: string
- :param scope: scope
- :type scope: string
- :param metric_data: metric_data
- :type bcm_model.MetricDatum array
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- scope = compat.convert_to_bytes(scope)
- path = b'/metricdata/%s/%s' % (user_id, scope)
- body = {
- "metricData": metric_data
- }
- return self._send_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def get_custom_metric_data(self, user_id=None, namespaces=None, metric_name=None,
- dimensions=None, statistics=None, start_time=None,
- end_time=None, cycle=None, config=None):
- """
- Return metric data of product instances owned by the authenticated user.
- This site may help you: https://cloud.baidu.com/doc/BCM/s/9jwvym3kb
- :param user_id:
- Master account ID
- :type user_id: string
- :param namespaces:
- Cloud product namespace, eg: BCE_BCC.
- :type namespaces: string
- :param metric_name:
- The metric name of baidu cloud monitor, eg: CpuIdlePercent.
- :type metric_name: string
- :param dimensions:
- Consists of dimensionName: dimensionValue.
- Use semicolons when items have multiple dimensions,
- such as dimensionName: dimensionValue; dimensionName: dimensionValue.
- Only one dimension value can be specified for the same dimension.
- eg: InstanceId:fakeid-2222
- :type dimensions: string
- :param statistics:
- According to the format of statistics1,statistics2,statistics3,
- the optional values are `average`, `maximum`, `minimum`, `sum`, `sampleCount`
- :type statistics: string
- :param start_time:
- Query start time.
- Please refer to the date and time, UTC date indication
- :type start_time: string
- :param end_time:
- Query end time.
- Please refer to the date and time, UTC date indication
- :type end_time: string
- :param cycle:
- Statistical period.
- Multiples of 60 in seconds (s).
- :type cycle: int
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- user_id = compat.convert_to_bytes(user_id)
- namespaces = compat.convert_to_bytes(namespaces)
- metric_name = compat.convert_to_bytes(metric_name)
- path = b'/userId/%s/custom/namespaces/%s/metrics/%s/data' % (user_id, namespaces, metric_name)
- body = {
- "statistics": statistics,
- "dimensions": dimensions,
- "startTime": start_time,
- "endTime": end_time,
- "cycle": cycle
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body),
- body_parser=bcm_handler.parse_json_list, config=config)
- def push_custom_metric_data(self, user_id=None, namespace=None, metric_name=None,
- dimensions=None, value=None,
- timestamp=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param namespace:
- :type namespace: string
- :param metric_name:
- :type metric_name: string
- :param dimensions:
- :type dimensions: bcm_model.Dimension array
- :param value:
- :type value: double
- :param timestamp:
- :type timestamp: string
- :param config:
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- namespace = compat.convert_to_bytes(namespace)
- path = b'/userId/%s/custom/data' % (user_id)
- body = {
- "namespace": namespace,
- "metricName": metric_name,
- "dimensions": dimensions,
- "value": value,
- "timestamp": timestamp
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def create_site_http_task_config(self, user_id=None, task_name=None, address=None,
- method=None, post_content=None,
- advance_config=None, cycle=None, idc=None, timeout=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_name:
- :type task_name: string
- :param address:
- :type address: string
- :param method:
- :type method: string
- :param post_content:
- :type post_content: string
- :param advance_config:
- :type advance_config: bool
- :param cycle:
- :type cycle: int
- :param idc:
- :type idc: string
- :param timeout:
- :type timeout: int
- :param config:
- :type config
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/http/create' % (user_id)
- body = {
- "userId": user_id,
- "taskName": task_name,
- "address": address,
- "method": method,
- "postContent": post_content,
- "advanceConfig": advance_config,
- "cycle": cycle,
- "idc": idc,
- "timeout": timeout,
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def update_site_http_task_config(self, user_id=None, task_id=None, task_name=None, address=None,
- method=None, post_content=None,
- advance_config=None, cycle=None, idc=None, timeout=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_id:
- :type task_id: string
- :param task_name:
- :type task_name: string
- :param address:
- :type address: string
- :param method:
- :type method: string
- :param post_content:
- :type post_content: string
- :param advance_config:
- :type advance_config: bool
- :param cycle:
- :type cycle: int
- :param idc:
- :type idc: string
- :param timeout:
- :type timeout: int
- :param config:
- :type config
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/http/update' % (user_id)
- body = {
- "userId": user_id,
- "taskId": task_id,
- "taskName": task_name,
- "address": address,
- "method": method,
- "postContent": post_content,
- "advanceConfig": advance_config,
- "cycle": cycle,
- "idc": idc,
- "timeout": timeout,
- }
- return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
- def get_site_http_task_config(self, user_id=None, task_id=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_id:
- :type task_id: string
- :param config:
- :type config
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/http/detail' % (user_id)
- params = {}
- if task_id is not None:
- params["taskId"] = task_id
- return self._send_csm_request(http_methods.GET, path, params=params, config=config)
- def create_site_https_task_config(self, user_id=None, task_name=None, address=None,
- method=None, post_content=None,
- advance_config=None, cycle=None, idc=None, timeout=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_name:
- :type task_name: string
- :param address:
- :type address: string
- :param method:
- :type method: string
- :param post_content:
- :type post_content: string
- :param advance_config:
- :type advance_config: bool
- :param cycle:
- :type cycle: int
- :param idc:
- :type idc: string
- :param timeout:
- :type timeout: int
- :param config:
- :type config
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/https/create' % (user_id)
- body = {
- "userId": user_id,
- "taskName": task_name,
- "address": address,
- "method": method,
- "postContent": post_content,
- "advanceConfig": advance_config,
- "cycle": cycle,
- "idc": idc,
- "timeout": timeout,
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def update_site_https_task_config(self, user_id=None, task_id=None, task_name=None, address=None,
- method=None, post_content=None,
- advance_config=None, cycle=None, idc=None, timeout=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_id:
- :type task_id: string
- :param task_name:
- :type task_name: string
- :param address:
- :type address: string
- :param method:
- :type method: string
- :param post_content:
- :type post_content: string
- :param advance_config:
- :type advance_config: bool
- :param cycle:
- :type cycle: int
- :param idc:
- :type idc: string
- :param timeout:
- :type timeout: int
- :param config:
- :type config
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/https/update' % (user_id)
- body = {
- "userId": user_id,
- "taskId": task_id,
- "taskName": task_name,
- "address": address,
- "method": method,
- "postContent": post_content,
- "advanceConfig": advance_config,
- "cycle": cycle,
- "idc": idc,
- "timeout": timeout,
- }
- return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
- def get_site_https_task_config(self, user_id=None, task_id=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_id:
- :type task_id: string
- :param config:
- :type config
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/https/detail' % (user_id)
- params = {}
- if task_id is not None:
- params["taskId"] = task_id
- return self._send_csm_request(http_methods.GET, path, params=params, config=config)
- def create_site_ping_task_config(self, user_id=None, task_name=None, address=None,
- packet_count=None, packet_loss_rate=None, cycle=None, idc=None,
- timeout=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_name:
- :type task_name: string
- :param address:
- :type address: string
- :param packet_count:
- :type packet_count: int
- :param packet_loss_rate:
- :type packet_loss_rate: int
- :param cycle:
- :type cycle: int
- :param idc:
- :type idc: string
- :param timeout:
- :type timeout: int
- :param config:
- :type config
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/ping/create' % (user_id)
- body = {
- "userId": user_id,
- "taskName": task_name,
- "address": address,
- "packetCount": packet_count,
- "packetLossRate": packet_loss_rate,
- "cycle": cycle,
- "idc": idc,
- "timeout": timeout,
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def update_site_ping_task_config(self, user_id=None, task_id=None, task_name=None, address=None,
- packet_count=None, packet_loss_rate=None, cycle=None, idc=None,
- timeout=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_id:
- :type task_id: string
- :param task_name:
- :type task_name: string
- :param address:
- :type address: string
- :param packet_count:
- :type packet_count: int
- :param packet_loss_rate:
- :type packet_loss_rate: int
- :param cycle:
- :type cycle: int
- :param idc:
- :type idc: string
- :param timeout:
- :type timeout: int
- :param config:
- :type config
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/ping/update' % (user_id)
- body = {
- "userId": user_id,
- "taskId": task_id,
- "taskName": task_name,
- "address": address,
- "packetCount": packet_count,
- "packetLossRate": packet_loss_rate,
- "cycle": cycle,
- "idc": idc,
- "timeout": timeout,
- }
- return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
- def get_site_ping_task_config(self, user_id=None, task_id=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_id:
- :type task_id: string
- :param config:
- :type config
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/ping/detail' % (user_id)
- params = {}
- if task_id is not None:
- params["taskId"] = task_id
- return self._send_csm_request(http_methods.GET, path, params=params, config=config)
- def create_site_tcp_task_config(self, user_id=None, task_name=None, address=None,
- port=None, advance_config=None, cycle=None, idc=None, timeout=None,
- input_type=None, output_type=None, input=None, expected_output=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_name:
- :type task_name: string
- :param address:
- :type address: string
- :param method:
- :type method: string
- :param post_content:
- :type post_content: string
- :param advance_config:
- :type advance_config: bool
- :param cycle:
- :type cycle: int
- :param idc:
- :type idc: string
- :param timeout:
- :type timeout: int
- :param config:
- :type config
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/tcp/create' % (user_id)
- body = {
- "userId": user_id,
- "taskName": task_name,
- "address": address,
- "port": port,
- "advanceConfig": advance_config,
- "inputType": input_type,
- "outputType": output_type,
- "input": input,
- "expectedOutput": expected_output,
- "cycle": cycle,
- "idc": idc,
- "timeout": timeout,
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def update_site_tcp_task_config(self, user_id=None, task_id=None, task_name=None, address=None,
- port=None, advance_config=None, cycle=None, idc=None, timeout=None,
- input_type=None, output_type=None, input=None, expected_output=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_id:
- :type task_id: string
- :param task_name:
- :type task_name: string
- :param address:
- :type address: string
- :param port:
- :type port: int
- :param post_content:
- :type post_content: string
- :param advance_config:
- :type advance_config: bool
- :param cycle:
- :type cycle: int
- :param idc:
- :type idc: string
- :param timeout:
- :type timeout: int
- :param input_type:
- :type input_type: int
- :param output_type:
- :type output_type: int
- :param input:
- :type input: string
- :param expected_output:
- :type expected_output: string
- :param config:
- :type config
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/tcp/update' % (user_id)
- body = {
- "userId": user_id,
- "taskId": task_id,
- "taskName": task_name,
- "address": address,
- "port": port,
- "advanceConfig": advance_config,
- "inputType": input_type,
- "outputType": output_type,
- "input": input,
- "expectedOutput": expected_output,
- "cycle": cycle,
- "idc": idc,
- "timeout": timeout,
- }
- return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
- def get_site_tcp_task_config(self, user_id=None, task_id=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_id:
- :type task_id: string
- :param config:
- :type config
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/tcp/detail' % (user_id)
- params = {}
- if task_id is not None:
- params["taskId"] = task_id
- return self._send_csm_request(http_methods.GET, path, params=params, config=config)
- def create_site_udp_task_config(self, user_id=None, task_name=None, address=None,
- port=None, advance_config=None, cycle=None, idc=None, timeout=None,
- input_type=None, output_type=None, input=None, expected_output=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_name:
- :type task_name: string
- :param address:
- :type address: string
- :param method:
- :type method: string
- :param post_content:
- :type post_content: string
- :param advance_config:
- :type advance_config: bool
- :param cycle:
- :type cycle: int
- :param idc:
- :type idc: string
- :param timeout:
- :type timeout: int
- :param config:
- :type config
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/udp/create' % (user_id)
- body = {
- "userId": user_id,
- "taskName": task_name,
- "address": address,
- "port": port,
- "advanceConfig": advance_config,
- "inputType": input_type,
- "outputType": output_type,
- "input": input,
- "expectedOutput": expected_output,
- "cycle": cycle,
- "idc": idc,
- "timeout": timeout,
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def update_site_udp_task_config(self, user_id=None, task_id=None, task_name=None, address=None,
- port=None, advance_config=None, cycle=None, idc=None, timeout=None,
- input_type=None, output_type=None, input=None, expected_output=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_id:
- :type task_id: string
- :param task_name:
- :type task_name: string
- :param address:
- :type address: string
- :param port:
- :type port: int
- :param post_content:
- :type post_content: string
- :param advance_config:
- :type advance_config: bool
- :param cycle:
- :type cycle: int
- :param idc:
- :type idc: string
- :param timeout:
- :type timeout: int
- :param input_type:
- :type input_type: int
- :param output_type:
- :type output_type: int
- :param input:
- :type input: string
- :param expected_output:
- :type expected_output: string
- :param config:
- :type config
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/udp/update' % (user_id)
- body = {
- "userId": user_id,
- "taskId": task_id,
- "taskName": task_name,
- "address": address,
- "port": port,
- "advanceConfig": advance_config,
- "inputType": input_type,
- "outputType": output_type,
- "input": input,
- "expectedOutput": expected_output,
- "cycle": cycle,
- "idc": idc,
- "timeout": timeout,
- }
- return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
- def get_site_udp_task_config(self, user_id=None, task_id=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_id:
- :type task_id: string
- :param config:
- :type config
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/udp/detail' % (user_id)
- params = {}
- if task_id is not None:
- params["taskId"] = task_id
- return self._send_csm_request(http_methods.GET, path, params=params, config=config)
- def create_site_ftp_task_config(self, user_id=None, task_name=None, address=None,
- port=None, anonymous_login=None, cycle=None, idc=None, timeout=None,
- user_name=None, password=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_name:
- :type task_name: string
- :param address:
- :type address: string
- :param port:
- :type port: int
- :param post_content:
- :type post_content: string
- :param anonymous_login:
- :type anonymous_login: bool
- :param cycle:
- :type cycle: int
- :param idc:
- :type idc: string
- :param timeout:
- :type timeout: int
- :param user_name:
- :type user_name: string
- :param password:
- :type password: string
- :param config:
- :type config
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/ftp/create' % (user_id)
- body = {
- "userId": user_id,
- "taskName": task_name,
- "address": address,
- "port": port,
- "anonymousLogin": anonymous_login,
- "userName": user_name,
- "password": password,
- "cycle": cycle,
- "idc": idc,
- "timeout": timeout,
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def update_site_ftp_task_config(self, user_id=None, task_id=None, task_name=None, address=None,
- port=None, anonymous_login=None, cycle=None, idc=None, timeout=None,
- user_name=None, password=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_id:
- :type task_id: string
- :param task_name:
- :type task_name: string
- :param address:
- :type address: string
- :param port:
- :type port: int
- :param post_content:
- :type post_content: string
- :param anonymous_login:
- :type anonymous_login: bool
- :param cycle:
- :type cycle: int
- :param idc:
- :type idc: string
- :param timeout:
- :type timeout: int
- :param user_name:
- :type user_name: string
- :param password:
- :type password: string
- :param config:
- :type config
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/ftp/update' % (user_id)
- body = {
- "userId": user_id,
- "taskId": task_id,
- "taskName": task_name,
- "address": address,
- "port": port,
- "anonymousLogin": anonymous_login,
- "userName": user_name,
- "password": password,
- "cycle": cycle,
- "idc": idc,
- "timeout": timeout,
- }
- return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
- def get_site_ftp_task_config(self, user_id=None, task_id=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_id:
- :type task_id: string
- :param config:
- :type config
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/ftp/detail' % (user_id)
- params = {}
- if task_id is not None:
- params["taskId"] = task_id
- return self._send_csm_request(http_methods.GET, path, params=params, config=config)
- def create_site_dns_task_config(self, user_id=None, task_name=None, address=None,
- cycle=None, idc=None, timeout=None,
- server=None, resolve_type=None, kidnap_white=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_name:
- :type task_name: string
- :param address:
- :type address: string
- :param post_content:
- :type post_content: string
- :param cycle:
- :type cycle: int
- :param idc:
- :type idc: string
- :param timeout:
- :type timeout: int
- :param server:
- :type server: string
- :param resolve_type:
- :type resolve_type: ENUM {'RECURSION', 'ITERATION'}
- :param kidnap_white:
- :type kidnap_white: string
- :param config:
- :type config
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/dns/create' % (user_id)
- body = {
- "userId": user_id,
- "taskName": task_name,
- "address": address,
- "server": server,
- "resolveType": resolve_type,
- "kidnapWhite": kidnap_white,
- "cycle": cycle,
- "idc": idc,
- "timeout": timeout,
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def update_site_dns_task_config(self, user_id=None, task_id=None, task_name=None, address=None,
- cycle=None, idc=None, timeout=None,
- server=None, resolve_type=None, kidnap_white=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_id:
- :type task_id: string
- :param task_name:
- :type task_name: string
- :param address:
- :type address: string
- :param post_content:
- :type post_content: string
- :param cycle:
- :type cycle: int
- :param idc:
- :type idc: string
- :param timeout:
- :type timeout: int
- :param server:
- :type server: string
- :param resolve_type:
- :type resolve_type: ENUM {'RECURSION', 'ITERATION'}
- :param kidnap_white:
- :type kidnap_white: string
- :param config:
- :type config
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/dns/update' % (user_id)
- body = {
- "userId": user_id,
- "taskId": task_id,
- "taskName": task_name,
- "address": address,
- "server": server,
- "resolveType": resolve_type,
- "kidnapWhite": kidnap_white,
- "cycle": cycle,
- "idc": idc,
- "timeout": timeout,
- }
- return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
- def get_site_dns_task_config(self, user_id=None, task_id=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_id:
- :type task_id: string
- :param config:
- :type config
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/dns/detail' % (user_id)
- params = {}
- if task_id is not None:
- params["taskId"] = task_id
- return self._send_csm_request(http_methods.GET, path, params=params, config=config)
- def get_site_task_config_list(self, user_id=None, query=None, type=None, page_no=None, page_size=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param query:
- :type query: string
- :param type:
- :type type: string
- :param page_no:
- :type page_no: int
- :param page_size:
- :type page_size: int
- :param config:
- :type config:
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/list' % (user_id)
- if query is None:
- query = "NAME:"
- params = {
- b'query': query,
- b'type': type,
- }
- if page_no is None:
- params[b'pageNo'] = 1
- else:
- params[b'pageNo'] = page_no
- if page_size is None:
- params[b'pageSize'] = 10
- else:
- params[b'pageSize'] = page_size
- return self._send_csm_request(http_methods.GET, path, params=params, config=config)
- def delete_site_task_config(self, user_id=None, task_id=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_Id:
- :type task_Id: string
- :param config:
- :type config:
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/delete' % (user_id)
- params = {
- b'taskId': task_id,
- }
- return self._send_csm_request(http_methods.DELETE, path, params=params, config=config)
- def get_site_task_config_info(self, user_id=None, task_id=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_Id:
- :type task_Id: string
- :param config:
- :type config:
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- task_id = compat.convert_to_bytes(task_id)
- path = b'/userId/%s/site/%s' % (user_id, task_id)
- return self._send_csm_request(http_methods.GET, path, config=config)
- def create_site_alarm_config(self, user_id=None, task_id=None, comment=None, alias_name=None,
- level=None, action_enabled=None, resume_actions=None, insufficient_actions=None,
- incident_action=None, insufficient_cycle=None, rules=None, region=None,
- callback_url=None, method=None, site_monitor=None, tag=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_id:
- :type task_id: string
- :param comment:
- :type comment: string
- :param alias_name:
- :type alias_name: string
- :param level:
- :type level: ENUM {'NOTICE', 'WARNING', 'CRITICAL', 'MAJOR', 'CUSTOM'}
- :param action_enabled:
- :type action_enabled: bool
- :param resume_actions:
- :type :type user_id: string: string
- :param insufficient_actions:
- :type insufficient_actions: string
- :param incident_action:
- :type incident_action: string
- :param insufficient_cycle:
- :type insufficient_cycle: int
- :param rules:
- :type rules: list of SiteAlarmRule
- :param region:
- :type region: string
- :param callback_url:
- :type callback_url: string
- :param method:
- :type method: string
- :param site_monitor:
- :type site_monitor: string
- :param tag:
- :type tag: string
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/alarm/config/create' % (user_id)
- body = {
- "userId": user_id,
- "taskId": task_id,
- "comment": comment,
- "aliasName": alias_name,
- "level": level,
- "actionEnabled": action_enabled,
- "resumeActions": resume_actions,
- "insufficientActions": insufficient_actions,
- "incidentAction": incident_action,
- "insufficientCycle": insufficient_cycle,
- "rules": rules,
- "region": region,
- "callbackUrl": callback_url,
- "method": method,
- "siteMonitor": site_monitor,
- "tag": tag
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
- def delete_site_alarm_config(self, user_id=None, alarm_names=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param alarm_names:
- :type alarm_names: list
- :param config:
- :type config:
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/alarm/config/delete' % (user_id)
- body = {
- "alarmNames": alarm_names
- }
- return self._send_csm_request(http_methods.DELETE, path, body=json.dumps(body), config=config)
- def update_site_alarm_config(self, user_id=None, task_id=None, alarm_name=None, comment=None, alias_name=None,
- level=None, action_enabled=None, resume_actions=None, insufficient_actions=None,
- incident_action=None, insufficient_cycle=None, rules=None, region=None,
- callback_url=None, method=None, site_monitor=None, tag=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_id:
- :type task_id: string
- :param alarm_name:
- :type alarm_name: string
- :param comment:
- :type comment: string
- :param alias_name:
- :type alias_name: string
- :param level:
- :type level: ENUM {'NOTICE', 'WARNING', 'CRITICAL', 'MAJOR', 'CUSTOM'}
- :param action_enabled:
- :type action_enabled: bool
- :param resume_actions:
- :type :type user_id: string: string
- :param insufficient_actions:
- :type insufficient_actions: string
- :param incident_action:
- :type incident_action: string
- :param insufficient_cycle:
- :type insufficient_cycle: int
- :param rules:
- :type rules: list of SiteAlarmRule
- :param region:
- :type region: string
- :param callback_url:
- :type callback_url: string
- :param method:
- :type method: string
- :param site_monitor:
- :type site_monitor: string
- :param tag:
- :type tag: string
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/alarm/config/update' % (user_id)
- body = {
- "userId": user_id,
- "taskId": task_id,
- "alarmName": alarm_name,
- "comment": comment,
- "aliasName": alias_name,
- "level": level,
- "actionEnabled": action_enabled,
- "resumeActions": resume_actions,
- "insufficientActions": insufficient_actions,
- "incidentAction": incident_action,
- "insufficientCycle": insufficient_cycle,
- "rules": rules,
- "region": region,
- "callbackUrl": callback_url,
- "method": method,
- "siteMonitor": site_monitor,
- "tag": tag
- }
- return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
- def get_site_alarm_config_detail(self, user_id=None, alarm_name=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param alarm_name:
- :type alarm_name: string
- :param config:
- :type config:
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/alarm/config/detail' % (user_id)
- params = {
- b'alarmName': alarm_name,
- }
- return self._send_csm_request(http_methods.GET, path, params=params, config=config)
- def get_site_alarm_config_list(self, user_id=None, task_id=None, alarm_name=None,
- action_enabled=None, page_no=None, page_size=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_id:
- :type task_id: string
- :param alarm_name:
- :type alarm_name: string
- :param action_enabled:
- :type action_enabled: bool
- :param page_no:
- :type page_no: int
- :param page_size:
- :type page_size: int
- :param config:
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/alarm/config/list' % (user_id)
- params = {}
- if task_id is not None:
- params[b'taskId'] = task_id
- if alarm_name is not None:
- params[b'alarmName'] = alarm_name
- if action_enabled is not None:
- params[b'actionEnabled'] = action_enabled
- if page_no is None:
- params[b'pageNo'] = 1
- else:
- params[b'pageNo'] = page_no
- if page_size is None:
- params[b'pageSize'] = 10
- else:
- params[b'pageSize'] = page_size
- return self._send_csm_request(http_methods.GET, path, params=params, config=config)
- def block_site_alarm_config(self, user_id=None, alarm_name=None, namespace=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param alarm_name:
- :type alarm_name: string
- :param config:
- :type config:
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/alarm/config/block' % (user_id)
- params = {
- "alarmName": alarm_name,
- "namespace": namespace
- }
- return self._send_csm_request(http_methods.POST, path, params=params, config=config)
- def unblock_site_alarm_config(self, user_id=None, alarm_name=None, namespace=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param alarm_name:
- :type alarm_name: string
- :param config:
- :type config:
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/alarm/config/unblock' % (user_id)
- params = {
- "alarmName": alarm_name,
- "namespace": namespace
- }
- return self._send_csm_request(http_methods.POST, path, params=params, config=config)
- def get_site_metric_data(self, user_id=None, task_id=None, metric_name=None, statistics=None,
- start_time=None, end_time=None, cycle=None,
- dimensions=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_id:
- :type task_id: string
- :param metric_name:
- :type metric_name: string
- :param statistics:
- :type statistics: list
- :param start_time:
- :type start_time: string
- :param end_time:
- :type end_time: string
- :param cycle:
- :type cycle: int
- :param dimensions:
- :type dimensions: string
- :param config:
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/metricSiteData' % (user_id)
- params = {
- "taskId": task_id,
- }
- if metric_name is not None:
- params[b'metricName'] = metric_name
- if dimensions is not None:
- params[b'dimensions'] = dimensions
- if statistics is not None and len(statistics) > 0:
- params[b'statistics'] = ",".join(statistics)
- if start_time is not None:
- params[b'startTime'] = start_time
- if end_time is not None:
- params[b'endTime'] = end_time
- if cycle is not None:
- params[b'cycle'] = cycle
- return self._send_csm_request(http_methods.GET, path, params=params,
- body_parser=bcm_handler.parse_json_list, config=config)
- def get_site_overall_view(self, user_id=None, task_id=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_id:
- :type task_id: string
- :param config:
- :type config:
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/idc/overallView' % (user_id)
- params = {
- "taskId": task_id
- }
- return self._send_csm_request(http_methods.GET, path, params=params,
- body_parser=bcm_handler.parse_json_list, config=config)
- def get_site_provincial_view(self, user_id=None, task_id=None, isp=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_id:
- :type task_id: string
- :param isp:
- :type isp: string
- :param config:
- :type config:
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/idc/provincialView' % (user_id)
- params = {
- "taskId": task_id,
- "isp": isp
- }
- return self._send_csm_request(http_methods.GET, path, params=params,
- body_parser=bcm_handler.parse_json_list, config=config)
- def get_site_agent(self, user_id=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param config:
- :type config:
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/agent/list' % (user_id)
- return self._send_csm_request(http_methods.GET, path, body_parser=bcm_handler.parse_json_list, config=config)
- def get_site_agent_for_task(self, user_id=None, task_id=None, config=None):
- """
- :param user_id:
- :type user_id: string
- :param task_id:
- :type task_id: string
- :param config:
- :type config:
- :return:
- """
- user_id = compat.convert_to_bytes(user_id)
- path = b'/userId/%s/site/agent/idcIsp' % (user_id)
- params = {
- "taskId": task_id
- }
- return self._send_csm_request(http_methods.GET, path, params=params, config=config)
- def create_alarm_config(self, user_id, alias_name, scope, level, region, monitor_object, alarm_actions, rules,
- src_type="INSTANCE", ok_actions=None, insufficient_actions=None, config_type="NORMAL",
- insufficient_cycle=0, max_repeat_count=0, repeat_alarm_cycle=0, callback_url="",
- callback_token="", description="", config=None):
- """
- create alarm config
- This site may help you: https://cloud.baidu.com/doc/BCM/s/Vks8iqqnx
- :param user_id: master account id
- :type user_id: string
- :param alias_name: alarm config alias name
- :type alias_name: string
- :param scope: scope
- :type scope: string
- :param level: alarm level
- :type level: string
- :param region: alarm region
- :type region: string
- :param monitor_object: monitor object
- :type monitor_object: MonitorObject
- :param alarm_actions: alarm actions
- :type alarm_actions: string array
- :param rules: alarm rules
- :type rules: AlarmRule double dimensional array
- :param src_type: src type
- :type src_type: string
- :param ok_actions: ok actions
- :type ok_actions: string array
- :param insufficient_actions: insufficient actions
- :type insufficient_actions: string array
- :param config_type: alarm config type
- :type config_type: string
- :param insufficient_cycle: insufficient cycle
- :type insufficient_cycle: int
- :param max_repeat_count: max repeat count
- :type max_repeat_count: int
- :param repeat_alarm_cycle: repeat alarm cycle
- :type repeat_alarm_cycle: int
- :param callback_url: callback url
- :type callback_url: string
- :param callback_token: callback token
- :type callback_token: string
- :param description: description
- :type description: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(alias_name) <= 0:
- raise ValueError('alias_name should not be none or empty string')
- if len(scope) <= 0:
- raise ValueError('scope should not be none or empty string')
- if len(region) <= 0:
- raise ValueError('region should not be none or empty string')
- if len(level) <= 0:
- raise ValueError('level should not be none or empty string')
- if monitor_object is None:
- raise ValueError('monitor_object should not be none')
- if len(alarm_actions) <= 0:
- raise ValueError('alarm_actions should not be empty')
- if len(rules) <= 0:
- raise ValueError('rules should not be empty')
- if insufficient_actions is None:
- insufficient_actions = []
- if ok_actions is None:
- ok_actions = []
- path = b'/services/alarm/config/create'
- body = {
- "alarmDescription": description,
- "aliasName": alias_name,
- "userId": user_id,
- "scope": scope,
- "region": region,
- "level": level,
- "monitorObject": monitor_object,
- "alarmActions": alarm_actions,
- "okActions": ok_actions,
- "insufficientActions": insufficient_actions,
- "srcType": src_type,
- "type": config_type,
- "insufficientCycle": insufficient_cycle,
- "maxRepeatCount": max_repeat_count,
- "repeatAlarmCycle": repeat_alarm_cycle,
- "callbackUrl": callback_url,
- "callbackToken": callback_token,
- "rules": rules,
- }
- self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
- def update_alarm_config(self, user_id, alarm_name, alias_name, scope, level, region,
- monitor_object, alarm_actions, rules,
- src_type="INSTANCE", ok_actions=None, insufficient_actions=None, config_type="NORMAL",
- insufficient_cycle=0, max_repeat_count=0, repeat_alarm_cycle=0, callback_url="",
- callback_token="", description="", config=None):
- """
- update alarm config
- This site may help you: https://cloud.baidu.com/doc/BCM/s/Vks8iqqnx
- :param user_id: master account id
- :type user_id: string
- :param alarm_name: alarm config name
- :type alarm_name: string
- :param alias_name: alarm config alias name
- :type alias_name: string
- :param scope: scope
- :type scope: string
- :param level: alarm level
- :type level: string
- :param region: alarm region
- :type region: string
- :param monitor_object: monitor object
- :type monitor_object: MonitorObject
- :param alarm_actions: alarm actions
- :type alarm_actions: string array
- :param rules: alarm rules
- :type rules: AlarmRule double dimensional array
- :param src_type: src type
- :type src_type: string
- :param ok_actions: ok actions
- :type ok_actions: string array
- :param insufficient_actions: insufficient actions
- :type insufficient_actions: string array
- :param config_type: alarm config type
- :type config_type: string
- :param insufficient_cycle: insufficient cycle
- :type insufficient_cycle: int
- :param max_repeat_count: max repeat count
- :type max_repeat_count: int
- :param repeat_alarm_cycle: repeat alarm cycle
- :type repeat_alarm_cycle: int
- :param callback_url: callback url
- :type callback_url: string
- :param callback_token: callback token
- :type callback_token: string
- :param description: description
- :type description: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(alias_name) <= 0:
- raise ValueError('alias_name should not be none or empty string')
- if len(alarm_name) <= 0:
- raise ValueError('alarm_name should not be none or empty string')
- if len(scope) <= 0:
- raise ValueError('scope should not be none or empty string')
- if len(region) <= 0:
- raise ValueError('region should not be none or empty string')
- if len(level) <= 0:
- raise ValueError('level should not be none or empty string')
- if monitor_object is None:
- raise ValueError('monitor_object should not be none')
- if len(alarm_actions) <= 0:
- raise ValueError('alarm_actions should not be empty')
- if len(rules) <= 0:
- raise ValueError('rules should not be empty')
- if insufficient_actions is None:
- insufficient_actions = []
- if ok_actions is None:
- ok_actions = []
- path = b'/services/alarm/config/update'
- body = {
- "alarmDescription": description,
- "alarmName": alarm_name,
- "aliasName": alias_name,
- "userId": user_id,
- "scope": scope,
- "region": region,
- "level": level,
- "monitorObject": monitor_object,
- "alarmActions": alarm_actions,
- "okActions": ok_actions,
- "insufficientActions": insufficient_actions,
- "srcType": src_type,
- "type": config_type,
- "insufficientCycle": insufficient_cycle,
- "maxRepeatCount": max_repeat_count,
- "repeatAlarmCycle": repeat_alarm_cycle,
- "callbackUrl": callback_url,
- "callbackToken": callback_token,
- "rules": rules,
- }
- self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
- def delete_alarm_config(self, user_id, alarm_name, scope, config=None):
- """
- delete alarm config
- This site may help you: https://cloud.baidu.com/doc/BCM/s/Vks8iqqnx
- :param user_id: master account id
- :type user_id: string
- :param alarm_name: alarm config name
- :type alarm_name: string
- :param scope: scope
- :type scope: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(alarm_name) <= 0:
- raise ValueError('alarm_name should not be none or empty string')
- if len(scope) <= 0:
- raise ValueError('scope should not be none or empty string')
- path = b'/services/alarm/config/delete'
- params = {
- b"alarmName": alarm_name,
- b"userId": user_id,
- b"scope": scope,
- }
- self._send_csm_request(http_methods.POST, path, params=params, config=config)
- def block_alarm_config(self, user_id, alarm_name, scope, config=None):
- """
- block alarm config
- This site may help you: https://cloud.baidu.com/doc/BCM/s/Vks8iqqnx
- :param user_id: master account id
- :type user_id: string
- :param alarm_name: alarm config name
- :type alarm_name: string
- :param scope: scope
- :type scope: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(alarm_name) <= 0:
- raise ValueError('alarm_name should not be none or empty string')
- if len(scope) <= 0:
- raise ValueError('scope should not be none or empty string')
- path = b'/services/alarm/config/block'
- params = {
- b"alarmName": alarm_name,
- b"userId": user_id,
- b"scope": scope,
- }
- self._send_csm_request(http_methods.POST, path, params=params, config=config)
- def unblock_alarm_config(self, user_id, alarm_name, scope, config=None):
- """
- unblock alarm config
- This site may help you: https://cloud.baidu.com/doc/BCM/s/Vks8iqqnx
- :param user_id: master account id
- :type user_id: string
- :param alarm_name: alarm config name
- :type alarm_name: string
- :param scope: scope
- :type scope: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(alarm_name) <= 0:
- raise ValueError('alarm_name should not be none or empty string')
- if len(scope) <= 0:
- raise ValueError('scope should not be none or empty string')
- path = b'/services/alarm/config/unblock'
- params = {
- b"alarmName": alarm_name,
- b"userId": user_id,
- b"scope": scope,
- }
- self._send_csm_request(http_methods.POST, path, params=params, config=config)
- def get_alarm_config_detail(self, user_id, alarm_name, scope, config=None):
- """
- get alarm config detail
- This site may help you: https://cloud.baidu.com/doc/BCM/s/Vks8iqqnx
- :param user_id: master account id
- :type user_id: string
- :param alarm_name: alarm config name
- :type alarm_name: string
- :param scope: scope
- :type scope: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(alarm_name) <= 0:
- raise ValueError('alarm_name should not be none or empty string')
- if len(scope) <= 0:
- raise ValueError('scope should not be none or empty string')
- path = b'/services/alarm/config'
- params = {
- b"alarmName": alarm_name,
- b"userId": user_id,
- b"scope": scope,
- }
- return self._send_csm_request(http_methods.GET, path, params=params, config=config)
- def get_single_instance_alarm_configs(self, user_id, scope, page_no, page_size,
- region="bj", alarm_name_prefix="", action_enabled=None, dimensions="",
- order="desc", config=None):
- """
- get alarm config detail
- This site may help you: https://cloud.baidu.com/doc/BCM/s/Vks8iqqnx
- :param user_id: master account id
- :type user_id: string
- :param scope: scope
- :type scope: string
- :param region: region
- :type region: string
- :param page_no: page no
- :type page_no: int
- :param page_size: page size
- :type page_size: int
- :param alarm_name_prefix: alarm name prefix
- :type alarm_name_prefix: string
- :param action_enabled: action enable flag
- :type action_enabled: bool
- :param dimensions: dimensions
- :type dimensions: string
- :param order: order
- :type order: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(scope) <= 0:
- raise ValueError('scope should not be none or empty string')
- if page_no <= 0:
- raise ValueError('page_no should be greater than 0')
- if page_size <= 0:
- raise ValueError('page_size should be greater than 0')
- path = b'/services/alarm/config/list'
- params = {
- b"region": region,
- b"userId": user_id,
- b"scope": scope,
- b"pageNo": page_no,
- b"pageSize": page_size,
- b"dimensions": dimensions,
- b"order": order,
- b"alarmNamePrefix": alarm_name_prefix,
- }
- if action_enabled is not None:
- if action_enabled:
- params["actionEnabled"] = "true"
- else:
- params["actionEnabled"] = "false"
- return self._send_csm_request(http_methods.GET, path, params=params, config=config)
- def get_alarm_metrics(self, user_id, scope, region="bj", dimensions="", metric_type="", locale="", config=None):
- """
- get alarm config detail
- This site may help you: https://cloud.baidu.com/doc/BCM/s/Vks8iqqnx
- :param user_id: master account id
- :type user_id: string
- :param scope: scope
- :type scope: string
- :param region: region
- :type region: string
- :param dimensions: dimensions
- :type dimensions: string
- :param metric_type: metric type
- :type metric_type: string
- :param locale: locale
- :type locale: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(scope) <= 0:
- raise ValueError('scope should not be none or empty string')
- path = b'/services/alarm/config/metrics'
- params = {
- b"region": region,
- b"userId": user_id,
- b"scope": scope,
- b"dimensions": dimensions,
- b"type": metric_type,
- b"locale": locale,
- }
- return self._send_csm_request(http_methods.GET, path, params=params,
- body_parser=bcm_handler.parse_json_list, config=config)
- def create_alarm_config_v2(self, user_id, alias_name, scope, target_type, level, region, actions, policies,
- target_instances=None, insufficient_period=0,
- alarm_repeat_interval=0, alarm_repeat_count=0,
- callback_url="", callback_token="", target_instance_tags=None,
- target_instance_groups=None, resource_type="Instance", config=None):
- """
- get alarm config detail
- This site may help you: https://cloud.baidu.com/doc/BCM/s/blhrp7kdx
- :param user_id: master account id
- :type user_id: string
- :param alias_name: alarm config alias name
- :type alias_name: string
- :param scope: scope
- :type scope: string
- :param target_type: alarm config target type
- :type target_type: string
- :param level: alarm level
- :type level: string
- :param region: alarm config region
- :type region: string
- :param actions: alarm actions
- :type actions: AlarmAction array
- :param policies: alarm config policies
- :type policies: AlarmConfigPolicy array
- :param target_instances: alarm config target instances
- :type target_instances: TargetInstance array
- :param insufficient_period: insufficient data pending period
- :type insufficient_period: int
- :param alarm_repeat_interval: alarm repeat interval
- :type alarm_repeat_interval: int
- :param alarm_repeat_count: alarm repeat count
- :type alarm_repeat_count: int
- :param callback_url: callback url
- :type callback_url: string
- :param callback_token: callback token
- :type callback_token: string
- :param target_instance_tags: target instance tags
- :type target_instance_tags: KV array
- :param target_instance_groups: target instance groups
- :type target_instance_groups: string array
- :param resource_type: resource type
- :type resource_type: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(scope) <= 0:
- raise ValueError('scope should not be none or empty string')
- if len(alias_name) <= 0:
- raise ValueError('alias_name should not be none or empty string')
- if len(target_type) <= 0:
- raise ValueError('target_type should not be none or empty string')
- if len(level) <= 0:
- raise ValueError('level should not be none or empty string')
- if len(region) <= 0:
- raise ValueError('region should not be none or empty string')
- if len(actions) <= 0:
- raise ValueError('actions should not be empty')
- if len(policies) <= 0:
- raise ValueError('policies should not be empty')
- if target_type == "TARGET_TYPE_MULTI_INSTANCES" and len(target_instances) <= 0:
- raise ValueError('target_instances should not be empty')
- if target_type == "TARGET_TYPE_INSTANCE_GROUP" and len(target_instance_groups) <= 0:
- raise ValueError('target_instance_groups should not be empty')
- if target_type == "TARGET_TYPE_INSTANCE_TAGS" and len(target_instance_tags) <= 0:
- raise ValueError('target_instance_tags should not be empty')
- if target_instance_groups is None:
- target_instance_groups = []
- if target_instance_tags is None:
- target_instance_tags = []
- if target_instances is None:
- target_instances = []
- path = b'/userId/%s/services/%s/alarm/config/create' % (user_id, scope)
- body = {
- "userId": user_id,
- "scope": scope,
- "aliasName": alias_name,
- "targetType": target_type,
- "resourceType": resource_type,
- "alarmLevel": level,
- "targetInstanceGroups": target_instance_groups,
- "targetInstanceTags": target_instance_tags,
- "callbackUrl": callback_url,
- "callbackToken": callback_token,
- "insufficientDataPendingPeriod": insufficient_period,
- "alarmRepeatInterval": alarm_repeat_interval,
- "alarmRepeatCount": alarm_repeat_count,
- "policies": policies,
- "targetInstances": target_instances,
- "actions": actions,
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config,
- version=BcmClient.version_v2)
- def update_alarm_config_v2(self, user_id, alarm_name, alias_name, scope, target_type, level, region,
- actions, policies, target_instances=None, insufficient_period=0,
- alarm_repeat_interval=0, alarm_repeat_count=0,
- callback_url="", callback_token="", target_instance_tags=None,
- target_instance_groups=None, resource_type="Instance", config=None):
- """
- get alarm config detail
- This site may help you: https://cloud.baidu.com/doc/BCM/s/blhrp7kdx
- :param user_id: master account id
- :type user_id: string
- :param alarm_name: alarm config name
- :type alarm_name: string
- :param alias_name: alarm config alias name
- :type alias_name: string
- :param scope: scope
- :type scope: string
- :param target_type: alarm config target type
- :type target_type: string
- :param level: alarm level
- :type level: string
- :param region: alarm config region
- :type region: string
- :param actions: alarm actions
- :type actions: AlarmAction array
- :param policies: alarm config policies
- :type policies: AlarmConfigPolicy array
- :param target_instances: alarm config target instances
- :type target_instances: TargetInstance array
- :param insufficient_period: insufficient data pending period
- :type insufficient_period: int
- :param alarm_repeat_interval: alarm repeat interval
- :type alarm_repeat_interval: int
- :param alarm_repeat_count: alarm repeat count
- :type alarm_repeat_count: int
- :param callback_url: callback url
- :type callback_url: string
- :param callback_token: callback token
- :type callback_token: string
- :param target_instance_tags: target instance tags
- :type target_instance_tags: KV array
- :param target_instance_groups: target instance groups
- :type target_instance_groups: string array
- :param resource_type: resource type
- :type resource_type: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- :return:
- :rtype baidubce.bce_response.BceResponse
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(scope) <= 0:
- raise ValueError('scope should not be none or empty string')
- if len(alarm_name) <= 0:
- raise ValueError('alarm_name should not be none or empty string')
- if len(alias_name) <= 0:
- raise ValueError('alias_name should not be none or empty string')
- if len(target_type) <= 0:
- raise ValueError('target_type should not be none or empty string')
- if len(level) <= 0:
- raise ValueError('level should not be none or empty string')
- if len(region) <= 0:
- raise ValueError('region should not be none or empty string')
- if len(actions) <= 0:
- raise ValueError('actions should not be empty')
- if len(policies) <= 0:
- raise ValueError('policies should not be empty')
- if target_type == "TARGET_TYPE_MULTI_INSTANCES" and len(target_instances) <= 0:
- raise ValueError('target_instances should not be empty')
- if target_type == "TARGET_TYPE_INSTANCE_GROUP" and len(target_instance_groups) <= 0:
- raise ValueError('target_instance_groups should not be empty')
- if target_type == "TARGET_TYPE_INSTANCE_TAGS" and len(target_instance_tags) <= 0:
- raise ValueError('target_instance_tags should not be empty')
- if target_instance_tags is None:
- target_instance_tags = []
- if target_instance_groups is None:
- target_instance_groups = []
- if target_instances is None:
- target_instances = []
- path = b'/userId/%s/services/%s/alarm/config/update' % (user_id, scope)
- body = {
- "userId": user_id,
- "scope": scope,
- "aliasName": alias_name,
- "alarmName": alarm_name,
- "targetType": target_type,
- "resourceType": resource_type,
- "alarmLevel": level,
- "targetInstanceGroups": target_instance_groups,
- "targetInstanceTags": target_instance_tags,
- "callbackUrl": callback_url,
- "callbackToken": callback_token,
- "insufficientDataPendingPeriod": insufficient_period,
- "alarmRepeatInterval": alarm_repeat_interval,
- "alarmRepeatCount": alarm_repeat_count,
- "policies": policies,
- "targetInstances": target_instances,
- "actions": actions,
- }
- return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config,
- version=BcmClient.version_v2)
- def block_alarm_config_v2(self, user_id, alarm_name, scope, config=None):
- """
- block alarm config v2
- This site may help you: https://cloud.baidu.com/doc/BCM/s/blhrp7kdx
- :param user_id: master account id
- :type user_id: string
- :param alarm_name: alarm config name
- :type alarm_name: string
- :param scope: scope
- :type scope: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(alarm_name) <= 0:
- raise ValueError('alarm_name should not be none or empty string')
- if len(scope) <= 0:
- raise ValueError('scope should not be none or empty string')
- path = b'/userId/%s/services/%s/alarm/config/block' % (user_id, scope)
- params = {
- b"alarmName": alarm_name
- }
- self._send_csm_request(http_methods.POST, path, params=params, config=config,
- version=BcmClient.version_v2)
- def unblock_alarm_config_v2(self, user_id, alarm_name, scope, config=None):
- """
- unblock alarm config v2
- This site may help you: https://cloud.baidu.com/doc/BCM/s/blhrp7kdx
- :param user_id: master account id
- :type user_id: string
- :param alarm_name: alarm config name
- :type alarm_name: string
- :param scope: scope
- :type scope: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(alarm_name) <= 0:
- raise ValueError('alarm_name should not be none or empty string')
- if len(scope) <= 0:
- raise ValueError('scope should not be none or empty string')
- path = b'/userId/%s/services/%s/alarm/config/unblock' % (user_id, scope)
- params = {
- b"alarmName": alarm_name
- }
- self._send_csm_request(http_methods.POST, path, params=params, config=config,
- version=BcmClient.version_v2)
- def get_alarm_config_detail_v2(self, user_id, alarm_name, scope, config=None):
- """
- get alarm config detail v2
- This site may help you: https://cloud.baidu.com/doc/BCM/s/blhrp7kdx
- :param user_id: master account id
- :type user_id: string
- :param alarm_name: alarm config name
- :type alarm_name: string
- :param scope: scope
- :type scope: string
- :param config:
- :type config: baidubce.BceClientConfiguration
- """
- if len(user_id) <= 0:
- raise ValueError('user_id should not be none or empty string')
- if len(alarm_name) <= 0:
- raise ValueError('alarm_name should not be none or empty string')
- if len(scope) <= 0:
- raise ValueError('scope should not be none or empty string')
- path = b'/userId/%s/services/%s/alarm/config' % (user_id, scope)
- params = {
- b"alarmName": alarm_name
- }
- self._send_csm_request(http_methods.GET, path, params=params, config=config, version=BcmClient.version_v2)
- @required(rules=list, insufficientActions=int, repeatAlarmCycle=int, maxRepeatCount=int)
- def create_custom_alarm_policy(self, user_id, alarm_name, namespace, level, comment="",
- action_enabled=True, policy_enabled=None, alarm_actions=None, ok_actions=None,
- insufficient_actions=None, insufficient_cycle=None, rules=None, region=None,
- callback_url=None, callback_token=None, tag="", repeat_alarm_cycle=0,
- max_repeat_count=0):
- """
- :param user_id:
- :type user_id: string
- :param alarm_name: alarm name
- :type alarm_name: string
- :param namespace: custom namespace
- :type namespace: string
- :param level: level
- :type level: string enum: NOTICE, NOTICE, CRITICAL, MAJOR
- :param comment: comment
- :type comment: string
- :param action_enabled: is action enabled
- :type action_enabled: bool
- :param policy_enabled: is policy enabled
- :type policy_enabled: bool
- :param alarm_actions: alarm actions
- :type alarm_actions: list
- :param ok_actions: ok actions
- :type ok_actions: list of string
- :param insufficient_actions: insufficient actions
- :type insufficient_actions: list of string
- :param insufficient_cycle: insufficient cycle
- :type insufficient_cycle: int
- :param rules: rules
- :type rules: list of CustomAlarmRule
- :param region: region
- :type region: string
- :param callback_url: callback url
- :type callback_url: string
- :param callback_token: callback token
- :type callback_token: string
- :param tag: tag
- :type tag: string
- :param repeat_alarm_cycle: repeat alarm cycle
- :type repeat_alarm_cycle: int
- :param max_repeat_count: max repeat count
- :type max_repeat_count: int
- :return
- :rtype baidubce.bce_response.BceResponse
- """
- path = b'/custom/alarm/configs/create'
- body = {
- "userId": user_id,
- "alarmName": alarm_name,
- "namespace": namespace,
- "level": level,
- "comment": comment,
- "actionEnabled": action_enabled,
- "policyEnabled": policy_enabled,
- "alarmActions": alarm_actions,
- "okActions": ok_actions,
- "insufficientActions": insufficient_actions,
- "insufficientCycle": insufficient_cycle,
- "rules": rules,
- "region": region,
- "callbackUrl": callback_url,
- "callbackToken": callback_token,
- "repeatAlarmCycle": repeat_alarm_cycle,
- "maxRepeatCount": max_repeat_count,
- "tag": tag
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
- @required(custom_alarm_list=list)
- def delete_custom_alarm_policy(self, custom_alarm_list):
- """
- :param custom_alarm_list:
- :type custom_alarm_list: list of custom alarm
- :return
- :rtype baidubce.bce_response.BceResponse
- """
- path = (b'/custom/alarm/configs/delete')
- body = {
- "customAlarmList": [
- ]
- }
- for custom_alarm in custom_alarm_list:
- body["customAlarmList"].append({
- "scope": custom_alarm["scope"],
- "userId": custom_alarm["userId"],
- "alarmName": custom_alarm["alarmName"]
- })
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
- @required(rules=list, insufficientActions=int, repeatAlarmCycle=int, maxRepeatCount=int)
- def update_custom_alarm_policy(self, user_id, alarm_name, namespace, level, comment="",
- action_enabled=True, policy_enabled=None, alarm_actions=None, ok_actions=None,
- insufficient_actions=None, insufficient_cycle=None, rules=None, region=None,
- callback_url=None, callback_token=None, tag="", repeat_alarm_cycle=0,
- max_repeat_count=0):
- """
- :param user_id:
- :type user_id: string
- :param alarm_name: alarm name
- :type alarm_name: string
- :param namespace: custom namespace
- :type namespace: string
- :param level: level
- :type level: string enum: NOTICE, NOTICE, CRITICAL, MAJOR
- :param comment: comment
- :type comment: string
- :param action_enabled: is action enabled
- :type action_enabled: bool
- :param policy_enabled: is policy enabled
- :type policy_enabled: bool
- :param alarm_actions: alarm actions
- :type alarm_actions: list
- :param ok_actions: ok actions
- :type ok_actions: list of string
- :param insufficient_actions: insufficient actions
- :type insufficient_actions: list of string
- :param insufficient_cycle: insufficient cycle
- :type insufficient_cycle: int
- :param rules: rules
- :type rules: list of CustomAlarmRule
- :param region: region
- :type region: string
- :param callback_url: callback url
- :type callback_url: string
- :param callback_token: callback token
- :type callback_token: string
- :param tag: tag
- :type tag: string
- :param repeat_alarm_cycle: repeat alarm cycle
- :type repeat_alarm_cycle: int
- :param max_repeat_count: max repeat count
- :type max_repeat_count: int
- :return
- :rtype baidubce.bce_response.BceResponse
- """
- if alarm_actions is None:
- alarm_actions = []
- if ok_actions is None:
- alarm_actions = []
- if insufficient_actions is None:
- insufficient_actions = []
- path = b'/custom/alarm/configs/update'
- body = {
- "userId": user_id,
- "alarmName": alarm_name,
- "namespace": namespace,
- "level": level,
- "comment": comment,
- "actionEnabled": action_enabled,
- "policyEnabled": policy_enabled,
- "alarmActions": alarm_actions,
- "okActions": ok_actions,
- "insufficientActions": insufficient_actions,
- "insufficientCycle": insufficient_cycle,
- "rules": rules,
- "region": region,
- "callbackUrl": callback_url,
- "callbackToken": callback_token,
- "repeatAlarmCycle": repeat_alarm_cycle,
- "maxRepeatCount": max_repeat_count,
- "tag": tag
- }
- return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body))
- def list_custom_policy(self, user_id, page_no, page_size, alarm_name=None, namespace=None, action_enabled=None):
- """
- :param user_id:
- :type user_id: string
- :param page_no: page number
- :type page_no: int
- :param page_size: page size
- :type page_size: int
- :param alarm_name: alarm name
- :type alarm_name: string
- :param namespace: namespace
- :type namespace: string
- :param action_enabled: is action enabled
- :type action_enabled: bool
- :return
- :rtype baidubce.bce_response.BceResponse
- """
- params = {
- b'pageNo': page_no,
- b'pageSize': page_size,
- b'userId': user_id,
- b'alarmName': alarm_name,
- b'actionEnabled': action_enabled,
- b'namespace': namespace
- }
- path = b'/custom/alarm/configs/list'
- return self._send_csm_request(http_methods.GET, path, params=params)
- def detail_custom_policy(self, user_id, namespace, alarm_name):
- """
- :param user_id:
- :type user_id: string
- :param namespace: namespace
- :type namespace: string
- :param alarm_name: alarm name
- :type alarm_name: string
- :return: Returns detailed information about a custom policy.
- :rtype: baidubce.bce_response.BceResponse
- """
- params = {
- b'userId': user_id,
- b'alarmName': alarm_name,
- b'namespace': namespace
- }
- path = b'/custom/alarm/configs/detail'
- return self._send_csm_request(http_methods.GET, path, params=params)
- def block_custom_policy(self, user_id, namespace, alarm_name):
- """
- :param user_id: User's identifier
- :type user_id: string
- :param namespace: Namespace
- :type namespace: string
- :param alarm_name: Alarm name
- :type alarm_name: string
- :return:
- :rtype: baidubce.bce_response.BceResponse
- """
- params = {
- b'userId': user_id,
- b'alarmName': alarm_name,
- b'namespace': namespace
- }
- path = b'/custom/alarm/configs/block'
- return self._send_csm_request(http_methods.POST, path, params=params)
- def unblock_custom_policy(self, user_id, namespace, alarm_name):
- """
- :param user_id: User's identifier
- :type user_id: str
- :param namespace: Namespace
- :type namespace: str
- :param alarm_name: Alarm name
- :type alarm_name: str
- :return:
- :rtype: baidubce.bce_response.BceResponse
- """
- params = {
- b'userId': user_id,
- b'alarmName': alarm_name,
- b'namespace': namespace
- }
- path = b'/custom/alarm/configs/unblock'
- return self._send_csm_request(http_methods.POST, path, params=params)
- def create_site_once_task(self, site_once_type, user_id, address, idc, timeout, protocol_type, once_config,
- task_type="NET_QUAILTY", ip_type="ipv4", advanced_flag=False,
- advanced_config=None, group_id=None):
- """
- :param site_once_type: Type of site
- :type site_once_type: str
- :param user_id: User's identifier
- :type user_id: str
- :param address: Address
- :type address: str
- :param idc: IDC
- :type idc: str
- :param timeout: Timeout
- :type timeout: int
- :param protocol_type: Protocol type
- :type protocol_type: str
- :param once_config: Configuration for once
- :type once_config: dict
- :param task_type: Task type
- :type task_type: str
- :param ip_type: IP type
- :type ip_type: str
- :param advanced_flag: Advanced flag
- :type advanced_flag: bool
- :param advanced_config: Advanced configuration
- :type advanced_config: dict
- :param group_id: Group identifier
- :type group_id: str
- :return:
- :rtype: baidubce.bce_response.BceResponse
- """
- types = ["HTTP", "HTTPS", "PING", "FTP", "TCP", "UDP", "DNS"]
- if site_once_type is not None and site_once_type not in types:
- raise ValueError('site_once_type must be none or one of %s' % str(types))
- path = (b'/site/once/%s/taskCreate' % compat.convert_to_bytes(site_once_type))
- if advanced_config is None:
- advanced_config = {}
- body = {
- "userId": user_id,
- "address": address,
- "idc": idc,
- "timeout": timeout,
- "protocolType": protocol_type,
- "onceConfig": once_config,
- "taskType": task_type,
- "ipType": ip_type,
- "advancedFlag": advanced_flag,
- "advancedConfig": advanced_config,
- "groupId": group_id
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
- def list_site_once_records(self, user_id=None, url=None, page_no=1, page_size=10,
- order=None, order_by=None, group_id=None):
- """
- :param user_id: User's identifier, defaults to None
- :type user_id: str
- :param url: URL
- :type url: str
- :param page_no: Page number
- :type page_no: int
- :param page_size: Page size
- :type page_size: int
- :param order: Order
- :type order: str
- :param order_by: Order by
- :type order_by: str
- :param group_id: Group identifier
- :type group_id: str
- :return:
- :rtype: baidubce.bce_response.BceResponse
- """
- path = b'/site/once/taskList'
- body = {
- "userId": user_id,
- "url": url,
- "pageNo": page_no,
- "pageSize": page_size,
- "order": order,
- "orderBy": order_by,
- "groupId": group_id
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
- def delete_site_once_record(self, user_id, site_id):
- """
- :param user_id: User's identifier
- :type user_id: str
- :param site_id: Site identifier
- :type site_id: str
- :return:
- :rtype: baidubce.bce_response.BceResponse
- """
- path = b'/site/once/taskDelete'
- body = {
- "userId": user_id,
- "siteId": site_id,
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
- def detail_site_once_result(self, user_id, site_id, page_no=1, page_size=10, order=None, order_by=None,
- filter_area=None, filter_isp=None):
- """
- :param user_id: User's identifier
- :type user_id: str
- :param site_id: Site identifier
- :type site_id: str
- :param page_no: Page number
- :type page_no: int
- :param page_size: Page size
- :type page_size: int
- :param order: Order
- :type order: str
- :param order_by: Order by
- :type order_by: str
- :param filter_area: Filter area
- :type filter_area: str
- :param filter_isp: Filter ISP
- :type filter_isp: str
- :return:
- :rtype: baidubce.bce_response.BceResponse
- """
- path = b'/site/once/loadData'
- body = {
- "userId": user_id,
- "siteId": site_id,
- "pageNo": page_no,
- "pageSize": page_size,
- "order": order,
- "orderBy": order_by,
- "filterArea": filter_area,
- "filterIsp": filter_isp
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
- def detail_site_once(self, user_id, site_id=None, site_ids=None, group_id=None, page_no=1, page_size=10,
- order=None, order_by=None, filter_area=None, filter_isp=None):
- """
- :param user_id: User's identifier
- :type user_id: str
- :param site_id: Site identifier
- :type site_id: str
- :param site_ids: List of site identifiers
- :type site_ids: list
- :param group_id: Group identifier
- :type group_id: str
- :param page_no: Page number
- :type page_no: int
- :param page_size: Page size
- :type page_size: int
- :param order: Order
- :type order: str
- :param order_by: Order by
- :type order_by: str
- :param filter_area: Filter area
- :type filter_area: str
- :param filter_isp: Filter ISP
- :type filter_isp: str
- :return:
- :rtype: baidubce.bce_response.BceResponse
- """
- path = b'/site/once/groupTask'
- body = {
- "userId": user_id,
- "siteId": site_id,
- "siteIds": site_ids,
- "groupId": group_id,
- "pageNo": page_no,
- "pageSize": page_size,
- "order": order,
- "orderBy": order_by,
- "filterArea": filter_area,
- "filterIsp": filter_isp
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
- def again_exec_site_once(self, user_id, site_id):
- """
- :param user_id: User's identifier
- :type user_id: str
- :param site_id: Site identifier
- :type site_id: str
- :return:
- :rtype: baidubce.bce_response.BceResponse
- """
- path = b'/site/once/createFromTask'
- body = {
- "userId": user_id,
- "siteId": site_id
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
- def list_site_once_history(self, user_id="", site_id="", group_id=""):
- """
- :param user_id: User's identifier
- :type user_id: str
- :param site_id: Site identifier
- :type site_id: str
- :param group_id: group identifier
- :type group_id: str
- :return:
- :rtype: baidubce.bce_response.BceResponse
- """
- path = b'/site/once/groupTaskList'
- body = {
- "userId": user_id,
- "groupId": group_id,
- "siteId": site_id
- }
- return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
- def get_site_once_agent(self, user_id, ip_type="ipv4"):
- """
- :param user_id: User's identifier
- :type user_id: str
- :param ip_type: the type of ip, enum: ipv4, ipv6
- :type ip_type: str
- :return:
- :rtype: baidubce.bce_response.BceResponse
- """
- types = ["ipv4", "ipv6"]
- if ip_type is not None and ip_type not in types:
- raise ValueError('ip_type must be none or one of %s' % str(types))
- params = {
- b'userId': user_id,
- b'ipType': ip_type,
- }
- path = b'/site/once/siteAgent'
- return self._send_csm_request(http_methods.GET, path, params=params)
- @required(user_id=str, scope=str, region=str, resource_type=str, dimensions=list,
- metric_names=list, timestamp=str, statistics=list, cycle=int)
- def get_multi_dimension_latest_metrics(self, user_id, scope, region=None, resource_type=None, dimensions=None,
- metric_names=None, timestamp=None, statistics=None, cycle=None):
- """
- :param user_id: str
- :param scope: str
- :param region: str
- :param resource_type: str
- :param dimensions: list
- :param metric_names: list
- :param timestamp: str
- :param statistics: list
- :param cycle: int
- :return:
- """
- if len(user_id) <= 0:
- raise ValueError("user_id should not be null")
- if len(scope) <= 0:
- raise ValueError("scope should not be null")
- if metric_names is None:
- raise ValueError("metric_names should not be null")
- if len(dimensions) > MAX_INSTANCE_NUMBER:
- raise ValueError("dimensions size cannot more than " + MAX_INSTANCE_NUMBER)
- if cycle is None:
- cycle = 60
- body = {
- "userId": user_id,
- "scope": scope,
- "cycle": cycle
- }
- metric_names_req = []
- for res in metric_names:
- metric_names_req.append(res)
- body["metricNames"] = metric_names_req
- if region is not None:
- body["region"] = region
- if resource_type is not None:
- body["resourceType"] = resource_type
- if dimensions is not None:
- dimensions_res = []
- for res in dimensions:
- dimensions_res.append(res)
- body["dimensions"] = dimensions_res
- if timestamp is not None:
- body["timestamp"] = timestamp
- if statistics is not None:
- body["statistics"] = statistics
- user_id = compat.convert_to_bytes(user_id)
- scope = compat.convert_to_bytes(scope)
- path = b'/userId/%s/services/%s/data/metricData/latest/batch' % (user_id, scope)
- return self._send_csm_request(http_methods.POST, path, version=b'/v2', body=json.dumps(body))
- def get_metrics_by_partial_dimensions(self, user_id, scope, statistics, metric_name, start_time, end_time,
- region=None, resource_type=None, dimensions=None, cycle=None,
- pageNo=None, pageSize=None):
- """
- :param user_id: str
- :param scope: str
- :param statistics: list
- :param metric_name: str
- :param start_time: str
- :param end_time: str
- :param region: str
- :param resource_type: str
- :param dimensions: list
- :param cycle: int
- :param pageNo: int
- :param pageSize: int
- :return:
- """
- if len(user_id) <= 0:
- raise ValueError("user_id should not be null")
- if len(scope) <= 0:
- raise ValueError("scope should not be null")
- if len(metric_name) <= 0:
- raise ValueError("metric_name should not be null")
- if len(start_time) <= 0:
- raise ValueError("start_time should not be null")
- if len(end_time) <= 0:
- raise ValueError("end_time should not be null")
- if len(statistics) <= 0:
- raise ValueError("statistics should not be null")
- if len(dimensions) > MAX_INSTANCE_NUMBER:
- raise ValueError("dimensions size cannot more than " + MAX_INSTANCE_NUMBER)
- body = {
- "userId": user_id,
- "scope": scope,
- "startTime": start_time,
- "endTime": end_time,
- "statistics": statistics,
- "metricName": metric_name
- }
- if region is not None:
- body["region"] = region
- if resource_type is not None:
- body["resourceType"] = resource_type
- if dimensions is not None:
- dimensions_res = []
- for res in dimensions:
- dimensions_res.append(res)
- body["dimensions"] = dimensions_res
- if cycle is not None:
- body["cycle"] = cycle
- if pageNo is not None:
- body["pageNo"] = pageNo
- if pageSize is not None:
- body["pageSize"] = pageSize
- user_id = compat.convert_to_bytes(user_id)
- scope = compat.convert_to_bytes(scope)
- path = b'/userId/%s/services/%s/data/metricData/PartialDimension' % (user_id, scope)
- return self._send_csm_request(http_methods.POST, path, version=b'/v2', body=json.dumps(body))
- def get_all_data_metrics_v2(self, user_id, scope, region, dimensions, metric_names, statistics,
- start_time, end_time, type="Instance", cycle=60):
- """
- :param user_id: user_id
- :type string
- :param scope: scope
- :type string
- :param region: region
- :type string
- :param type: resource type
- :type string
- :param dimensions: dimensions
- :type double string array
- :param metric_names: metric names
- :type string array
- :param statistics: statistics
- :type string array
- :param cycle: cycle
- :type int
- :param start_time: start time
- :type string
- :param end_time: end time
- :type string
- :return:
- """
- if len(user_id) <= 0:
- raise ValueError("user_id should not be null")
- if len(scope) <= 0:
- raise ValueError("scope should not be null")
- if len(region) <= 0:
- raise ValueError("region should not be null")
- if metric_names is None:
- raise ValueError("metric_names should not be null")
- if dimensions is None:
- raise ValueError("dimensions should not be null")
- if statistics is None:
- raise ValueError("statistics should not be null")
- if len(dimensions) > MAX_INSTANCE_NUMBER:
- raise ValueError("dimensions size cannot more than " + MAX_INSTANCE_NUMBER)
- body = {
- "userId": user_id,
- "scope": scope,
- "cycle": cycle,
- "region": region,
- "startTime": start_time,
- "endTime": end_time,
- "metricNames": metric_names,
- "dimensions": dimensions,
- "statistics": statistics
- }
- if type is not None:
- body["type"] = type
- path = b'/data/metricAllData'
- return self._send_csm_request(http_methods.POST, path, version=b'/v2', body=json.dumps(body))
- def batch_get_all_data_metrics_v2(self, user_id, scope, region, dimensions, metric_names, statistics,
- start_time, end_time, type="Instance", cycle=60):
- """
- :param user_id: user_id
- :type string
- :param scope: scope
- :type string
- :param region: region
- :type string
- :param dimensions: dimensions
- :type double dimensional dict array
- :param metric_names: metric names
- :type string array
- :param statistics: statistics
- :type string array
- :param start_time: start time
- :type string
- :param end_time: end time
- :type string
- :param type: type
- :type string
- :param cycle: cycle
- :type int
- :return:
- """
- if len(user_id) <= 0:
- raise ValueError("user_id should not be null")
- if len(scope) <= 0:
- raise ValueError("scope should not be null")
- if len(region) <= 0:
- raise ValueError("region should not be null")
- if len(metric_names) <= 0:
- raise ValueError("metric_names should not be null")
- if len(dimensions) <= 0:
- raise ValueError("dimensions should not be null")
- if len(statistics) <= 0:
- raise ValueError("statistics should not be null")
- if len(dimensions) > MAX_INSTANCE_NUMBER:
- raise ValueError("dimensions size cannot more than " + MAX_INSTANCE_NUMBER)
- body = {
- "userId": user_id,
- "scope": scope,
- "cycle": cycle,
- "region": region,
- "startTime": start_time,
- "endTime": end_time,
- "metricNames": metric_names,
- "dimensions": dimensions,
- "statistics": statistics
- }
- if type is not None:
- body["type"] = type
- path = b'/data/metricAllData/batch'
- return self._send_csm_request(http_methods.POST, path, version=b'/v2', body=json.dumps(body))
- def get_metric_dimension_top(self, user_id, scope, region, dimensions, metric_name, statistics, labels,
- start_time, end_time, order="top", topNum=10):
- """
- :param user_id: user_id
- :type string
- :param scope: scope
- :type string
- :param region: region
- :type string
- :param dimensions: dimensions
- :type map
- :param metric_name: metric_name
- :type string
- :param statistics: statistics
- :type string
- :param labels: labels
- :type set
- :param start_time: start_time
- :type string
- :param end_time: end_time
- :type string
- :param order: order default top
- :type string
- :param topNum: topNum default 10
- :type int
- :return:
- """
- if len(user_id) <= 0:
- raise ValueError("user_id should not be null")
- if len(scope) <= 0:
- raise ValueError("scope should not be null")
- if len(region) <= 0:
- raise ValueError("region should not be null")
- if len(metric_name) <= 0:
- raise ValueError("metric_name should not be null")
- if len(dimensions) <= 0:
- raise ValueError("dimensions should not be null")
- if len(labels) <= 0:
- raise ValueError("lables should not be null")
- if len(statistics) <= 0:
- raise ValueError("statistics should not be null")
- if len(start_time) <= 0:
- raise ValueError("start_time should not be null")
- if len(end_time) <= 0:
- raise ValueError("end_time should not be null")
- body = {
- "userId": user_id,
- "scope": scope,
- "region": region,
- "startTime": start_time,
- "endTime": end_time,
- "metricName": metric_name,
- "dimensions": dimensions,
- "statistics": statistics,
- "labels": labels,
- "order": order,
- "topNum": topNum,
- }
- path = b'/dimensions/top'
- return self._send_csm_request(http_methods.POST, path, version=b'/v2', body=json.dumps(body))
|