bcm_client.py 206 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950
  1. # Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
  4. # except in compliance with the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the
  9. # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  10. # either express or implied. See the License for the specific language governing permissions
  11. # and limitations under the License.
  12. """
  13. This module provides a client class for BCM.
  14. """
  15. import copy
  16. import json
  17. import sys
  18. import uuid
  19. from baidubce import bce_base_client, utils, compat
  20. from baidubce.auth import bce_v1_signer
  21. from baidubce.http import handler, bce_http_client, http_methods
  22. from baidubce.services.bcm import bcm_handler, bcm_model
  23. from baidubce.utils import required
  24. if sys.version_info[0] == 2:
  25. value_type = (str, unicode)
  26. else:
  27. value_type = (str, bytes)
  28. MAX_INSTANCE_NUMBER = 100
  29. class BcmClient(bce_base_client.BceBaseClient):
  30. """
  31. BCM base sdk client
  32. """
  33. prefix = b'/json-api'
  34. csm_prefix = b'/csm/api'
  35. event_prefix = b'/event-api'
  36. version = b'/v1'
  37. version_v2 = b'/v2'
  38. content_type_header_key = b"content-type"
  39. content_type_header_value = b"application/json;charset=UTF-8"
  40. request_id_header_key = b"x-bce-request-id"
  41. def __init__(self, config=None):
  42. bce_base_client.BceBaseClient.__init__(self, config)
  43. def _merge_config(self, config=None):
  44. if config is None:
  45. return self.config
  46. else:
  47. new_config = copy.copy(self.config)
  48. new_config.merge_non_none_values(config)
  49. return new_config
  50. def _send_request(self, http_method, path,
  51. body=None, headers=None, params=None,
  52. config=None, body_parser=None):
  53. config = self._merge_config(config)
  54. if body_parser is None:
  55. body_parser = handler.parse_json
  56. return bce_http_client.send_request(
  57. config, bce_v1_signer.sign, [handler.parse_error, body_parser],
  58. http_method, BcmClient.prefix + BcmClient.version + path, body, headers, params)
  59. def _send_csm_request(self, http_method, path, version=b'/v1',
  60. body=None, headers=None, params=None, config=None, body_parser=None):
  61. config = self._merge_config(config)
  62. if body_parser is None:
  63. body_parser = handler.parse_json
  64. if headers is None:
  65. headers = {}
  66. if self.content_type_header_key not in headers:
  67. headers[self.content_type_header_key] = self.content_type_header_value
  68. if self.request_id_header_key not in headers:
  69. headers[self.request_id_header_key] = uuid.uuid4()
  70. return bce_http_client.send_request(
  71. config, bce_v1_signer.sign, [bcm_handler.parse_error, body_parser],
  72. http_method, BcmClient.csm_prefix + version + path, body, headers, params)
  73. def _send_event_request(self, http_method, path,
  74. body=None, headers=None, params=None, config=None, body_parser=None):
  75. config = self._merge_config(config)
  76. if body_parser is None:
  77. body_parser = handler.parse_json
  78. if headers is None:
  79. headers = {}
  80. if self.content_type_header_key not in headers:
  81. headers[self.content_type_header_key] = self.content_type_header_value
  82. if self.request_id_header_key not in headers:
  83. headers[self.request_id_header_key] = uuid.uuid4()
  84. return bce_http_client.send_request(
  85. config, bce_v1_signer.sign, [bcm_handler.parse_error, body_parser],
  86. http_method, BcmClient.event_prefix + BcmClient.version + path, body, headers, params)
  87. def get_metric_data(self, user_id=None, scope=None, metric_name=None,
  88. dimensions=None, statistics=None, start_time=None,
  89. end_time=None, period_in_second=None, config=None):
  90. """
  91. Return metric data of product instances owned by the authenticated user.
  92. This site may help you: https://cloud.baidu.com/doc/BCM/s/9jwvym3kb
  93. :param user_id:
  94. Master account ID
  95. :type user_id: string
  96. :param scope:
  97. Cloud product namespace, eg: BCE_BCC.
  98. :type scope: string
  99. :param metric_name:
  100. The metric name of baidu cloud monitor, eg: CpuIdlePercent.
  101. :type metric_name: string
  102. :param dimensions:
  103. Consists of dimensionName: dimensionValue.
  104. Use semicolons when items have multiple dimensions,
  105. such as dimensionName: dimensionValue; dimensionName: dimensionValue.
  106. Only one dimension value can be specified for the same dimension.
  107. eg: InstanceId:fakeid-2222
  108. :type dimensions: string
  109. :param statistics:
  110. According to the format of statistics1,statistics2,statistics3,
  111. the optional values are `average`, `maximum`, `minimum`, `sum`, `sampleCount`
  112. :type statistics: string
  113. :param start_time:
  114. Query start time.
  115. Please refer to the date and time, UTC date indication
  116. :type start_time: string
  117. :param end_time:
  118. Query end time.
  119. Please refer to the date and time, UTC date indication
  120. :type end_time: string
  121. :param period_in_second:
  122. Statistical period.
  123. Multiples of 60 in seconds (s).
  124. :type period_in_second: int
  125. :param config:
  126. :type config: baidubce.BceClientConfiguration
  127. :return:
  128. :rtype baidubce.bce_response.BceResponse
  129. """
  130. user_id = compat.convert_to_bytes(user_id)
  131. scope = compat.convert_to_bytes(scope)
  132. metric_name = compat.convert_to_bytes(metric_name)
  133. path = b'/metricdata/%s/%s/%s' % (user_id, scope, metric_name)
  134. params = {}
  135. if dimensions is not None:
  136. params[b'dimensions'] = dimensions
  137. if statistics is not None:
  138. params[b'statistics[]'] = statistics
  139. if start_time is not None:
  140. params[b'startTime'] = start_time
  141. if end_time is not None:
  142. params[b'endTime'] = end_time
  143. if period_in_second is not None:
  144. params[b'periodInSecond'] = period_in_second
  145. return self._send_request(http_methods.GET, path, params=params, config=config)
  146. def get_batch_metric_data(self, user_id=None, scope=None, metric_name=None,
  147. dimensions=None, statistics=None, start_time=None,
  148. end_time=None, period_in_second=None, config=None):
  149. """
  150. Return batch metric data of product instances owned by the authenticated user.
  151. :param user_id:
  152. Master account ID
  153. :type user_id: string
  154. :param scope:
  155. Cloud product namespace, eg: BCE_BCC.
  156. :type scope: string
  157. :param metric_name:
  158. The metric name of baidu cloud monitor, eg: CpuIdlePercent.
  159. Use comma when items have multiple metrics,
  160. such as metric1,metric2,metric3.
  161. :type metric_name: string
  162. :param dimensions:
  163. Consists of dimensionName:dimensionValue.
  164. Use comma when items have multiple dimensions,
  165. such as dimensionName:dimensionValue,dimensionName:dimensionValue.
  166. Only one dimension value can be specified for the same dimension.
  167. eg: InstanceId:itk-1010,InstanceId:itk-1011
  168. :type dimensions: string
  169. :param statistics:
  170. According to the format of statistics1,statistics2,statistics3,
  171. the optional values are `average`, `maximum`, `minimum`, `sum`, `sampleCount`
  172. :type statistics: string
  173. :param start_time:
  174. Query start time.
  175. Please refer to the date and time, UTC date indication
  176. :type start_time: string
  177. :param end_time:
  178. Query end time.
  179. Please refer to the date and time, UTC date indication
  180. :type end_time: string
  181. :param period_in_second:
  182. Statistical period.
  183. Multiples of 60 in seconds (s).
  184. :type period_in_second: int
  185. :param config:
  186. :type config: baidubce.BceClientConfiguration
  187. :return:
  188. :rtype baidubce.bce_response.BceResponse
  189. """
  190. user_id = compat.convert_to_bytes(user_id)
  191. scope = compat.convert_to_bytes(scope)
  192. path = b'/metricdata/batch/%s/%s' % (user_id, scope)
  193. params = {}
  194. if metric_name is not None:
  195. params[b'metricName[]'] = metric_name
  196. if dimensions is not None:
  197. params[b'dimensions[]'] = dimensions
  198. if statistics is not None:
  199. params[b'statistics[]'] = statistics
  200. if start_time is not None:
  201. params[b'startTime'] = start_time
  202. if end_time is not None:
  203. params[b'endTime'] = end_time
  204. if period_in_second is not None:
  205. params[b'periodInSecond'] = period_in_second
  206. return self._send_request(http_methods.GET, path, params=params, config=config)
  207. def create_namespace(self, user_id, name, namespace_alias=None, comment=None, config=None):
  208. """
  209. create a custom namespace for custom monitor
  210. This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
  211. :param user_id:
  212. master account id
  213. :type user_id: string
  214. :param name:
  215. namespace name
  216. :type name: string
  217. :param namespace_alias:
  218. namespace alias name
  219. :type namespace_alias: string
  220. :param comment:
  221. namespace comment
  222. :type user_id: string
  223. :param config:
  224. :type config: baidubce.BceClientConfiguration
  225. :return:
  226. :rtype baidubce.bce_response.BceResponse
  227. """
  228. if len(user_id) <= 0:
  229. raise ValueError('user_id should not be none or empty string')
  230. if len(name) <= 0:
  231. raise ValueError('name should not be none or empty string')
  232. path = b'/userId/%s/custom/namespaces/create' % compat.convert_to_bytes(user_id)
  233. body = {
  234. "userId": user_id,
  235. "name": name,
  236. "namespaceAlias": namespace_alias,
  237. "comment": comment,
  238. }
  239. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  240. def batch_delete_namespaces(self, user_id, names, config=None):
  241. """
  242. create a custom namespace for custom monitor
  243. This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
  244. :param user_id:
  245. master account id
  246. :type user_id: string
  247. :param names:
  248. namespace name collection
  249. :type names: string array
  250. :param config:
  251. :type config: baidubce.BceClientConfiguration
  252. :return:
  253. :rtype baidubce.bce_response.BceResponse
  254. """
  255. if len(user_id) <= 0:
  256. raise ValueError('user_id should not be none or empty string')
  257. if len(names) <= 0:
  258. raise ValueError('names should not be empty')
  259. path = b'/userId/%s/custom/namespaces/delete' % compat.convert_to_bytes(user_id)
  260. body = {
  261. "userId": user_id,
  262. "names": names,
  263. }
  264. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  265. def update_namespace(self, user_id, name, namespace_alias=None, comment=None, config=None):
  266. """
  267. update a custom namespace for custom monitor
  268. This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
  269. :param user_id:
  270. master account id
  271. :type user_id: string
  272. :param name:
  273. namespace name
  274. :type name: string
  275. :param namespace_alias:
  276. namespace alias name
  277. :type namespace_alias: string
  278. :param comment:
  279. namespace comment
  280. :type user_id: string
  281. :param config:
  282. :type config: baidubce.BceClientConfiguration
  283. :return:
  284. :rtype baidubce.bce_response.BceResponse
  285. """
  286. if len(user_id) <= 0:
  287. raise ValueError('user_id should not be none or empty string')
  288. if len(name) <= 0:
  289. raise ValueError('name should not be none or empty string')
  290. path = b'/userId/%s/custom/namespaces/update' % compat.convert_to_bytes(user_id)
  291. body = {
  292. "userId": user_id,
  293. "name": name,
  294. "namespaceAlias": namespace_alias,
  295. "comment": comment,
  296. }
  297. return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
  298. def list_namespaces(self, user_id, name=None, page_no=None, page_size=None, config=None):
  299. """
  300. list custom namespaces
  301. This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
  302. :param user_id:
  303. master account id
  304. :type user_id: string
  305. :param name:
  306. namespace name prefix for query
  307. :type name: string
  308. :param page_no:
  309. page number
  310. :type page_no: int
  311. :param page_size:
  312. page size
  313. :type page_size: int
  314. :param config:
  315. :type config: baidubce.BceClientConfiguration
  316. :return:
  317. :rtype baidubce.bce_response.BceResponse
  318. """
  319. if len(user_id) <= 0:
  320. raise ValueError('user_id should not be none or empty string')
  321. path = b'/userId/%s/custom/namespaces/list' % compat.convert_to_bytes(user_id)
  322. params = {
  323. b'userId': user_id,
  324. }
  325. if name is not None:
  326. params[b'name'] = name
  327. if page_no is None:
  328. params[b'pageNo'] = 1
  329. else:
  330. params[b'pageNo'] = page_no
  331. if page_size is None:
  332. params[b'pageSize'] = 10
  333. else:
  334. params[b'pageSize'] = page_size
  335. return self._send_csm_request(http_methods.GET, path, params=params, config=config)
  336. def create_namespace_metric(self, user_id, namespace, metric_name,
  337. metric_alias=None, unit=None, cycle=None, dimensions=None, config=None):
  338. """
  339. create custom metric in one namespace
  340. This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
  341. :param user_id:
  342. master account id
  343. :type user_id: string
  344. :param namespace:
  345. namespace name
  346. :type namespace: string
  347. :param metric_name:
  348. custom metric name
  349. :type metric_name: string
  350. :param metric_alias:
  351. custom metric alias
  352. :type metric_alias: string
  353. :param unit:
  354. custom metric unit
  355. :type unit: string
  356. :param unit:
  357. custom metric unit
  358. :type unit: string
  359. :param cycle:
  360. custom metric cycle
  361. :type cycle: int
  362. :param dimensions:
  363. custom dimension collection
  364. :type dimensions: CustomDimensionModel array
  365. :param config:
  366. :type config: baidubce.BceClientConfiguration
  367. :return:
  368. :rtype baidubce.bce_response.BceResponse
  369. """
  370. if len(user_id) <= 0:
  371. raise ValueError('user_id should not be none or empty string')
  372. if len(namespace) <= 0:
  373. raise ValueError('namespace should not be none or empty string')
  374. if len(metric_name) <= 0:
  375. raise ValueError('metric_name should not be none or empty string')
  376. path = (b'/userId/%s/custom/namespaces/%s/metrics/create' %
  377. (compat.convert_to_bytes(user_id), compat.convert_to_bytes(namespace)))
  378. body = {
  379. "userId": user_id,
  380. "namespace": namespace,
  381. "metricName": metric_name,
  382. }
  383. if metric_alias is not None:
  384. body["metricAlias"] = metric_alias
  385. if unit is not None:
  386. body["unit"] = unit
  387. if cycle is not None:
  388. body["cycle"] = cycle
  389. else:
  390. body["cycle"] = 60
  391. if dimensions is not None:
  392. body["dimensions"] = dimensions
  393. else:
  394. body["dimensions"] = []
  395. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  396. def batch_delete_namespace_metrics(self, user_id, namespace, ids, config=None):
  397. """
  398. batch delete custom metric in one namespace
  399. This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
  400. :param user_id:
  401. master account id
  402. :type user_id: string
  403. :param namespace:
  404. custom namespace name
  405. :type namespace: string
  406. :param ids:
  407. namespace metric id collection
  408. :type ids: int array
  409. :param config:
  410. :type config: baidubce.BceClientConfiguration
  411. :return:
  412. :rtype baidubce.bce_response.BceResponse
  413. """
  414. if len(user_id) <= 0:
  415. raise ValueError('user_id should not be none or empty string')
  416. if len(ids) <= 0:
  417. raise ValueError('ids should not be empty')
  418. path = (b'/userId/%s/custom/namespaces/%s/metrics/delete' %
  419. (compat.convert_to_bytes(user_id), compat.convert_to_bytes(namespace)))
  420. body = {
  421. "userId": user_id,
  422. "namespace": namespace,
  423. "ids": ids,
  424. }
  425. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  426. def update_namespace_metric(self, user_id, namespace, metric_name,
  427. metric_alias=None, unit=None, cycle=None, dimensions=None, config=None):
  428. """
  429. update custom metric in one namespace
  430. This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
  431. :param user_id:
  432. master account id
  433. :type user_id: string
  434. :param namespace:
  435. namespace name
  436. :type namespace: string
  437. :param metric_name:
  438. custom metric name
  439. :type metric_name: string
  440. :param metric_alias:
  441. custom metric alias
  442. :type metric_alias: string
  443. :param unit:
  444. custom metric unit
  445. :type unit: string
  446. :param unit:
  447. custom metric unit
  448. :type unit: string
  449. :param cycle:
  450. custom metric cycle
  451. :type cycle: int
  452. :param dimensions:
  453. custom dimension collection
  454. :type dimensions: CustomDimensionModel array
  455. :param config:
  456. :type config: baidubce.BceClientConfiguration
  457. :return:
  458. :rtype baidubce.bce_response.BceResponse
  459. """
  460. if len(user_id) <= 0:
  461. raise ValueError('user_id should not be none or empty string')
  462. if len(namespace) <= 0:
  463. raise ValueError('namespace should not be none or empty string')
  464. if len(metric_name) <= 0:
  465. raise ValueError('metric_name should not be none or empty string')
  466. if cycle is None:
  467. raise ValueError('cycle should not be none')
  468. path = (b'/userId/%s/custom/namespaces/%s/metrics/%s' % (compat.convert_to_bytes(user_id),
  469. compat.convert_to_bytes(namespace),
  470. compat.convert_to_bytes(metric_name)))
  471. body = {
  472. "userId": user_id,
  473. "namespace": namespace,
  474. "metricName": metric_name,
  475. "cycle": cycle,
  476. }
  477. if metric_alias is not None:
  478. body["metricAlias"] = metric_alias
  479. if unit is not None:
  480. body["unit"] = unit
  481. if dimensions is not None:
  482. body["dimensions"] = dimensions
  483. return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
  484. def list_namespace_metrics(self, user_id, namespace,
  485. metric_name=None, metric_alias=None, page_no=None, page_size=None, config=None):
  486. """
  487. list custom metric in one namespace
  488. This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
  489. :param user_id:
  490. master account id
  491. :type user_id: string
  492. :param namespace:
  493. namespace name
  494. :type namespace: string
  495. :param metric_name:
  496. custom metric name prefix for query
  497. :type metric_name: string
  498. :param metric_alias:
  499. custom metric alias prefix for query
  500. :type metric_alias: string
  501. :param page_no:
  502. page number
  503. :type page_no: int
  504. :param page_size:
  505. page size
  506. :type page_size: int
  507. :param config:
  508. :type config: baidubce.BceClientConfiguration
  509. :return:
  510. :rtype baidubce.bce_response.BceResponse
  511. """
  512. if len(user_id) <= 0:
  513. raise ValueError('user_id should not be none or empty string')
  514. if len(namespace) <= 0:
  515. raise ValueError('namespace should not be none or empty string')
  516. path = b'/userId/%s/custom/namespaces/metrics' % compat.convert_to_bytes(user_id)
  517. params = {
  518. b'userId': user_id,
  519. b'namespace': namespace,
  520. }
  521. if metric_name is not None:
  522. params[b'metricName'] = metric_name
  523. if metric_alias is not None:
  524. params[b'metricAlias'] = metric_alias
  525. if page_no is None:
  526. params[b'pageNo'] = 1
  527. else:
  528. params[b'pageNo'] = page_no
  529. if page_size is None:
  530. params[b'pageSize'] = 10
  531. else:
  532. params[b'pageSize'] = page_size
  533. return self._send_csm_request(http_methods.GET, path, params=params, config=config)
  534. def get_custom_metric(self, user_id, namespace, metric_name, config=None):
  535. """
  536. get custom metric detail
  537. This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
  538. :param user_id:
  539. master account id
  540. :type user_id: string
  541. :param namespace:
  542. namespace name
  543. :type namespace: string
  544. :param metric_name:
  545. custom metric name
  546. :type metric_name: string
  547. :param config:
  548. :type config: baidubce.BceClientConfiguration
  549. :return:
  550. :rtype baidubce.bce_response.BceResponse
  551. """
  552. if len(user_id) <= 0:
  553. raise ValueError('user_id should not be none or empty string')
  554. if len(namespace) <= 0:
  555. raise ValueError('namespace should not be none or empty string')
  556. if len(metric_name) <= 0:
  557. raise ValueError('metric_name should not be none or empty string')
  558. path = (b'/userId/%s/custom/namespaces/%s/metrics/%s' % (compat.convert_to_bytes(user_id),
  559. compat.convert_to_bytes(namespace),
  560. compat.convert_to_bytes(metric_name)))
  561. params = {}
  562. return self._send_csm_request(http_methods.GET, path, params=params, config=config)
  563. def create_namespace_event(self, user_id, namespace, event_name, event_level,
  564. event_name_alias=None, comment=None, config=None):
  565. """
  566. create custom event in one namespace
  567. This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
  568. :param user_id:
  569. master account id
  570. :type user_id: string
  571. :param namespace:
  572. namespace name
  573. :type namespace: string
  574. :param event_level:
  575. custom event level
  576. :type event_level: ENUM {'NOTICE', 'WARNING', 'MAJOR', 'CRITICAL'}
  577. :param event_name:
  578. custom event name
  579. :type event_name: string
  580. :param event_name_alias:
  581. custom event alias
  582. :type event_name_alias: string
  583. :param comment:
  584. custom event comment
  585. :type comment: string
  586. :param config:
  587. :type config: baidubce.BceClientConfiguration
  588. :return:
  589. :rtype baidubce.bce_response.BceResponse
  590. """
  591. if len(user_id) <= 0:
  592. raise ValueError('user_id should not be none or empty string')
  593. if len(namespace) <= 0:
  594. raise ValueError('namespace should not be none or empty string')
  595. if len(event_name) <= 0:
  596. raise ValueError('event_name should not be none or empty string')
  597. if not bcm_model.EventLevel.contains(event_level):
  598. raise ValueError('event_level must be one of %s' % str(bcm_model.EventLevel.all_event_levels()))
  599. path = b'/custom/event/configs/create'
  600. body = {
  601. "userId": user_id,
  602. "namespace": namespace,
  603. "eventName": event_name,
  604. "eventLevel": event_level,
  605. }
  606. if event_name_alias is not None:
  607. body["eventNameAlias"] = event_name_alias
  608. if comment is not None:
  609. body["comment"] = comment
  610. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  611. def batch_delete_namespace_events(self, user_id, namespace, names, config=None):
  612. """
  613. batch delete custom metric in one namespace
  614. This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
  615. :param user_id:
  616. master account id
  617. :type user_id: string
  618. :param namespace:
  619. custom namespace name
  620. :type namespace: string
  621. :param names:
  622. namespace event name collection
  623. :type names: string array
  624. :param config:
  625. :type config: baidubce.BceClientConfiguration
  626. :return:
  627. :rtype baidubce.bce_response.BceResponse
  628. """
  629. if len(user_id) <= 0:
  630. raise ValueError('user_id should not be none or empty string')
  631. if len(names) <= 0:
  632. raise ValueError('names should not be empty')
  633. path = b'/custom/event/configs/delete'
  634. body = {
  635. "userId": user_id,
  636. "namespace": namespace,
  637. "names": names,
  638. }
  639. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  640. def update_namespace_event(self, user_id, namespace, event_name, event_level,
  641. event_name_alias=None, comment=None, config=None):
  642. """
  643. update custom event in one namespace
  644. This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
  645. :param user_id:
  646. master account id
  647. :type user_id: string
  648. :param namespace:
  649. namespace name
  650. :type namespace: string
  651. :param event_level:
  652. custom event level
  653. :type event_level: ENUM {'NOTICE', 'WARNING', 'MAJOR', 'CRITICAL'}
  654. :param event_name:
  655. custom event name
  656. :type event_name: string
  657. :param event_name_alias:
  658. custom event alias
  659. :type event_name_alias: string
  660. :param comment:
  661. custom event comment
  662. :type comment: string
  663. :param config:
  664. :type config: baidubce.BceClientConfiguration
  665. :return:
  666. :rtype baidubce.bce_response.BceResponse
  667. """
  668. if len(user_id) <= 0:
  669. raise ValueError('user_id should not be none or empty string')
  670. if len(namespace) <= 0:
  671. raise ValueError('namespace should not be none or empty string')
  672. if len(event_name) <= 0:
  673. raise ValueError('event_name should not be none or empty string')
  674. if not bcm_model.EventLevel.contains(event_level):
  675. raise ValueError('event_level must be one of %s' % str(bcm_model.EventLevel.all_event_levels()))
  676. path = b'/custom/event/configs/update'
  677. body = {
  678. "userId": user_id,
  679. "namespace": namespace,
  680. "eventName": event_name,
  681. "eventLevel": event_level,
  682. }
  683. if event_name_alias is not None:
  684. body["eventNameAlias"] = event_name_alias
  685. if comment is not None:
  686. body["comment"] = comment
  687. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  688. def list_namespace_events(self, user_id, namespace,
  689. name=None, event_level=None, page_no=None, page_size=None, config=None):
  690. """
  691. list custom event in one namespace
  692. This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
  693. :param user_id:
  694. master account id
  695. :type user_id: string
  696. :param namespace:
  697. namespace name
  698. :type namespace: string
  699. :param name:
  700. custom metric name prefix for query
  701. :type name: string
  702. :param event_level:
  703. custom metric level
  704. :type event_level: None or ENUM {'NOTICE', 'WARNING', 'MAJOR', 'CRITICAL'}
  705. :param page_no:
  706. page number
  707. :type page_no: int
  708. :param page_size:
  709. page size
  710. :type page_size: int
  711. :param config:
  712. :type config: baidubce.BceClientConfiguration
  713. :return:
  714. :rtype baidubce.bce_response.BceResponse
  715. """
  716. if len(user_id) <= 0:
  717. raise ValueError('user_id should not be none or empty string')
  718. if len(namespace) <= 0:
  719. raise ValueError('namespace should not be none or empty string')
  720. if event_level is not None and (not bcm_model.EventLevel.contains(event_level)):
  721. raise ValueError('event_level must be none or one of %s' % str(bcm_model.EventLevel.all_event_levels()))
  722. path = b'/custom/event/configs/list'
  723. params = {
  724. b'userId': user_id,
  725. b'namespace': namespace,
  726. }
  727. if name is not None:
  728. params[b'name'] = name
  729. if event_level is not None:
  730. params[b'event_level'] = event_level
  731. if page_no is None:
  732. params[b'pageNo'] = 1
  733. else:
  734. params[b'pageNo'] = page_no
  735. if page_size is None:
  736. params[b'pageSize'] = 10
  737. else:
  738. params[b'pageSize'] = page_size
  739. return self._send_csm_request(http_methods.GET, path, params=params, config=config)
  740. def get_custom_event(self, user_id, namespace, event_name, config=None):
  741. """
  742. get custom event detail
  743. This site may help you: https://cloud.baidu.com/doc/BCM/s/cktnhszhv
  744. :param user_id:
  745. master account id
  746. :type user_id: string
  747. :param namespace:
  748. namespace name
  749. :type namespace: string
  750. :param event_name:
  751. custom event name
  752. :type event_name: string
  753. :param config:
  754. :type config: baidubce.BceClientConfiguration
  755. :return:
  756. :rtype baidubce.bce_response.BceResponse
  757. """
  758. if len(user_id) <= 0:
  759. raise ValueError('user_id should not be none or empty string')
  760. if len(namespace) <= 0:
  761. raise ValueError('namespace should not be none or empty string')
  762. if len(event_name) <= 0:
  763. raise ValueError('metric_name should not be none or empty string')
  764. path = b'/custom/event/configs/detail'
  765. params = {
  766. b"userId": user_id,
  767. b"namespace": namespace,
  768. b"eventName": event_name,
  769. }
  770. return self._send_csm_request(http_methods.GET, path, params=params, config=config)
  771. @required(page_no=int, page_size=int)
  772. def list_notify_group(self, page_no, page_size, name=None):
  773. """
  774. :param name: notify name
  775. :type name: string
  776. :param page_no: page number
  777. :type page_no: int
  778. :param page_size: page size
  779. :type page_size: int
  780. :return
  781. :rtype baidubce.bce_response.BceResponse
  782. """
  783. headers = {self.content_type_header_key: self.content_type_header_value}
  784. path = b'/alarm/notify/group/list'
  785. body = {
  786. "name": name,
  787. "pageNo": page_no,
  788. "pageSize": page_size
  789. }
  790. return self._send_request(http_methods.POST, path, headers=headers, body=json.dumps(body))
  791. @required(page_no=int, page_size=int)
  792. def list_notify_party(self, page_no, page_size, name=None):
  793. """
  794. :param name: notify name
  795. :type name: string
  796. :param page_no: page number
  797. :type page_no: int
  798. :param page_size: page size
  799. :type page_size: int
  800. :return
  801. :rtype baidubce.bce_response.BceResponse
  802. """
  803. headers = {self.content_type_header_key: self.content_type_header_value}
  804. path = b'/alarm/notify/party/list'
  805. body = {
  806. "name": name,
  807. "pageNo": page_no,
  808. "pageSize": page_size
  809. }
  810. return self._send_request(http_methods.POST, path, headers=headers, body=json.dumps(body))
  811. @required(page_no=int, page_size=int, notifications=list, members=list)
  812. def create_action(self, user_id, notifications, members, alias, disable_times=None, action_callbacks=None):
  813. """
  814. :param user_id:
  815. :type user_id: string
  816. :param notifications:
  817. :type notifications: list of bcm_model.Notification
  818. :param members:
  819. :type members: list of bcm_model.Member
  820. :param alias: action's alias
  821. :type alias: string
  822. :param disable_times: disable time
  823. :type disable_times: list of bcm_model.DisableTime
  824. :param action_callbacks: list of action callback
  825. :type action_callbacks: list
  826. :return
  827. :rtype baidubce.bce_response.BceResponse
  828. """
  829. if disable_times is None:
  830. disable_times = []
  831. if action_callbacks is None:
  832. action_callbacks = []
  833. path = b'/userId/%s/action/create' % compat.convert_to_bytes(user_id)
  834. body = {
  835. "userId": user_id,
  836. "notifications": notifications,
  837. "members": members,
  838. "alias": alias,
  839. "disableTimes": disable_times,
  840. "actionCallBacks": action_callbacks
  841. }
  842. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
  843. def delete_action(self, user_id, name):
  844. """
  845. :param user_id:
  846. :type user_id: string
  847. :param name: action name
  848. :type name: string
  849. :return:
  850. :rtype baidubce.bce_response.BceResponse
  851. """
  852. path = b'/userId/%s/action/delete' % compat.convert_to_bytes(user_id)
  853. params = {b'name': name}
  854. return self._send_csm_request(http_methods.DELETE, path, params=params)
  855. @required(page_no=int, page_size=int)
  856. def list_action(self, user_id, page_no, page_size, name=None, order=None):
  857. """
  858. :param user_id:
  859. :type user_id: string
  860. :param page_no: page number
  861. :type page_no: int
  862. :param page_size: page size
  863. :type page_size: int
  864. :param name: action name
  865. :type name: string
  866. :param order: desc or asc
  867. :type name: string
  868. :return:
  869. :rtype baidubce.bce_response.BceResponse
  870. """
  871. path = b'/userId/%s/action/actionList' % compat.convert_to_bytes(user_id)
  872. body = {
  873. "name": name,
  874. "pageNo": page_no,
  875. "pageSize": page_size,
  876. "order": order
  877. }
  878. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
  879. @required(page_no=int, page_size=int, notifications=list, members=list)
  880. def update_action(self, user_id, name, notifications, members, alias, disable_times=None,
  881. action_callbacks=None):
  882. """
  883. :param user_id:
  884. :type user_id: string
  885. :param name: action name
  886. :type name: string
  887. :param notifications:
  888. :type notifications: list of bcm_model.Notification
  889. :param members:
  890. :type members: list of bcm_model.Member
  891. :param alias: action's alias
  892. :type alias: string
  893. :param disable_times: disable time
  894. :type disable_times: list of bcm_model.DisableTime
  895. :param action_callbacks: list of action callback
  896. :type action_callbacks: list
  897. :return
  898. :rtype baidubce.bce_response.BceResponse
  899. """
  900. if disable_times is None:
  901. disable_times = []
  902. if action_callbacks is None:
  903. action_callbacks = []
  904. path = b'/userId/%s/action/update' % compat.convert_to_bytes(user_id)
  905. body = {
  906. "productName": user_id,
  907. "name": name,
  908. "notifications": notifications,
  909. "members": members,
  910. "alias": alias,
  911. "disableTimes": disable_times,
  912. "actionCallBacks": action_callbacks,
  913. "source": "USER"
  914. }
  915. return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body))
  916. def log_extract(self, user_id, extract_rule, log_example):
  917. """
  918. :param user_id:
  919. :type user_id: string
  920. :param extract_rule: the log extract rule
  921. :type: string
  922. :param log_example: log example
  923. :type: string
  924. :return
  925. :rtype baidubce.bce_response.BceResponse
  926. """
  927. path = b'/userId/%s/application/logextract' % compat.convert_to_bytes(user_id)
  928. body = {
  929. "extractRule": extract_rule,
  930. "logExample": log_example
  931. }
  932. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body),
  933. body_parser=bcm_handler.parse_json_list)
  934. def query_metric_meta_for_application(self, user_id, app_name, task_name, metric_name, dimension_keys,
  935. instances=None):
  936. """
  937. :param user_id:
  938. :type user_id string
  939. :param app_name: application name
  940. :type app_name: string
  941. :param task_name: task name
  942. :type task_name: string
  943. :param metric_name:
  944. :type metric_name: string
  945. :param dimension_keys: multi dimension keys
  946. :type dimension_keys: list of string
  947. :param instances: multiple instance names
  948. :type instances: list of string
  949. :return
  950. :rtype baidubce.bce_response.BceResponse
  951. """
  952. path = (b'/userId/%s/application/%s/task/%s/metricMeta' % (compat.convert_to_bytes(user_id),
  953. compat.convert_to_bytes(app_name),
  954. compat.convert_to_bytes(task_name)))
  955. params = {b'metricName': metric_name, b'dimensionKeys': ",".join(dimension_keys)}
  956. print(params)
  957. if instances is not None and len(instances) > 0:
  958. params[b'instances'] = ",".join(instances)
  959. return self._send_csm_request(http_methods.GET, path, params=params)
  960. def query_metric_data_for_application(self, user_id, app_name, task_name, metric_name, start_time, end_time,
  961. instances=None, cycle=None, dimensions=None, statistics=None, aggr_data=None):
  962. """
  963. :param user_id:
  964. :type user_id: string
  965. :param app_name: application name
  966. :type app_name: string
  967. :param task_name: task name
  968. :type task_name: string
  969. :param metric_name: metric name
  970. :type metric_name: string
  971. :param start_time: start time, such as 2023-12-05T09:54:15Z
  972. :type start_time: string
  973. :param end_time: end time, such as 2023-12-05T09:54:15Z
  974. :type end_time: string
  975. :param instances: multiple instance names
  976. :type instances: list of string
  977. :param cycle: period time
  978. :type cycle: int
  979. :param dimensions: dimensions, such as ["httpMethod:POST___GET,path:apipath","httpMethod:POST,path:apipath1]
  980. :type dimensions: list of string
  981. :param statistics: statistics, enum: average, maximum, minimum, sum, sampleCount
  982. :type statistics: list of string
  983. :param aggr_data: is aggregation data
  984. :type aggr_data: bool
  985. :return
  986. :rtype baidubce.bce_response.BceResponse
  987. """
  988. path = (b'/userId/%s/application/%s/task/%s/metricData' % (compat.convert_to_bytes(user_id),
  989. compat.convert_to_bytes(app_name),
  990. compat.convert_to_bytes(task_name)))
  991. params = {b'startTime': start_time, b'endTime': end_time, b'metricName': metric_name}
  992. if statistics is not None and len(statistics) > 0:
  993. params[b'statistics'] = ",".join(statistics)
  994. if cycle is not None and cycle > 0:
  995. params[b'cycle'] = cycle
  996. if aggr_data is not None:
  997. params[b'aggrData'] = aggr_data
  998. if instances is not None and len(instances) > 0:
  999. params[b'instances'] = ",".join(instances)
  1000. if dimensions is not None and len(dimensions) > 0:
  1001. params[b'dimensions'] = ",".join(dimensions)
  1002. return self._send_csm_request(http_methods.GET, path, params=params, body_parser=bcm_handler.parse_json_list)
  1003. def list_alarm_metrics_for_application(self, user_id, app_name, task_name, search_name=None):
  1004. """
  1005. :param user_id:
  1006. :type user_id: string
  1007. :param app_name: application name
  1008. :type app_name: string
  1009. :param task_name: task name
  1010. :type task_name: string
  1011. :param search_name: metric name
  1012. :type search_name: string
  1013. :return
  1014. :rtype baidubce.bce_response.BceResponse
  1015. """
  1016. path = (b'/userId/%s/application/%s/%s/alarm/metrics' % (compat.convert_to_bytes(user_id),
  1017. compat.convert_to_bytes(app_name),
  1018. compat.convert_to_bytes(task_name)))
  1019. params = {}
  1020. if search_name is None:
  1021. params[b'searchName'] = search_name
  1022. return self._send_csm_request(http_methods.GET, path, params=params, body_parser=bcm_handler.parse_json_list)
  1023. def get_alarm_policy_for_application(self, user_id, alarm_name, app_name):
  1024. """
  1025. :param user_id:
  1026. :type user_id: string
  1027. :param app_name: application name
  1028. :type app_name: string
  1029. :param alarm_name: alarm name
  1030. :type alarm_name: string
  1031. :return
  1032. :rtype baidubce.bce_response.BceResponse
  1033. """
  1034. path = (b'/userId/%s/application/alarm/%s/config' % (compat.convert_to_bytes(user_id),
  1035. compat.convert_to_bytes(alarm_name)))
  1036. params = {b'appName': app_name}
  1037. return self._send_csm_request(http_methods.GET, path, params=params)
  1038. def delete_alarm_policy_for_application(self, user_id, alarm_name, app_name):
  1039. """
  1040. :param user_id:
  1041. :type user_id: string
  1042. :param app_name: application name
  1043. :type app_name: string
  1044. :param alarm_name: alarm name
  1045. :type alarm_name: string
  1046. :return
  1047. :rtype baidubce.bce_response.BceResponse
  1048. """
  1049. path = (b'/userId/%s/application/alarm/config' % compat.convert_to_bytes(user_id))
  1050. body = {
  1051. 'appName': app_name,
  1052. "alarmName": alarm_name
  1053. }
  1054. return self._send_csm_request(http_methods.DELETE, path, body=json.dumps(body))
  1055. @required(page_no=int, page_size=int)
  1056. def list_alarm_policy_for_application(self, user_id, page_no, page_size=None, app_name=None, alarm_name=None,
  1057. action_enabled=None, src_type=None, task_name=None):
  1058. """
  1059. :param user_id:
  1060. :type user_id: string
  1061. :param page_no: page number
  1062. :type page_no: int
  1063. :param app_name: application name
  1064. :type app_name: string
  1065. :param alarm_name: alarm name
  1066. :type alarm_name: string
  1067. :param action_enabled: is action enabled
  1068. :type action_enabled: bool
  1069. :param src_type: task type, enum: PROC,PORT,LOG,SCR
  1070. :type src_type: string
  1071. :param task_name: task name
  1072. :type task_name: string
  1073. :param page_size: page size
  1074. :type page_size: int
  1075. :return
  1076. :rtype baidubce.bce_response.BceResponse
  1077. """
  1078. path = (b'/userId/%s/application/alarm/config/list' % compat.convert_to_bytes(user_id))
  1079. params = {
  1080. b'pageNo': page_no,
  1081. b'pageSize': page_size,
  1082. b'appName': app_name,
  1083. b'alarmName': alarm_name,
  1084. b'actionEnabled': action_enabled,
  1085. b'srcType': src_type,
  1086. b'taskName': task_name,
  1087. }
  1088. return self._send_csm_request(http_methods.GET, path, params=params)
  1089. @required(rules=list)
  1090. def create_alarm_policy_for_application(self, user_id, alarm_description, alarm_name, app_name,
  1091. monitor_object_type, monitor_object, src_name, src_type, type, level,
  1092. rules, action_enabled=True, incident_actions=None, resume_actions=None,
  1093. insufficient_actions=None, insufficient_cycle=None, repeat_alarm_cycle=0,
  1094. max_repeat_count=0):
  1095. """
  1096. :param user_id:
  1097. :type user_id: string
  1098. :param alarm_description: alarm policy comment
  1099. :type alarm_description: string
  1100. :param alarm_name: unique alarm name in user_id
  1101. :type alarm_name: string
  1102. :param app_name: application name
  1103. :type app_name: string
  1104. :param monitor_object_type: monitor object type, enum: APP, SERVICE
  1105. :type monitor_object_type: string
  1106. :param monitor_object: application monitor object
  1107. :type monitor_object: bcm_model.ApplicationMonitorObject
  1108. :param src_name: task name
  1109. :type src_name: string
  1110. :param src_type: task type, enum: PROC,PORT,LOG,SCR
  1111. :type src_type: string
  1112. :param type: alarm type
  1113. :type type: string
  1114. :param level: alarm level
  1115. :type level: string
  1116. :param rules: list of application alarm rules
  1117. :type rules: list of ApplicationAlarmRule
  1118. :param action_enabled: is alarm action enabled
  1119. :type action_enabled: bool
  1120. :param incident_actions: The action to be taken in the alarm state
  1121. :type incident_actions: list of string
  1122. :param resume_actions: The action to be taken in the alarm resume
  1123. :type resume_actions: list of string
  1124. :param insufficient_actions:
  1125. :type insufficient_actions: list of string
  1126. :param insufficient_cycle: insufficient cycle
  1127. :type insufficient_cycle: int
  1128. :param repeat_alarm_cycle: repeat alarm_cycle
  1129. :type repeat_alarm_cycle: int
  1130. :param max_repeat_count: max repeat count
  1131. :type max_repeat_count: int
  1132. :return
  1133. :rtype baidubce.bce_response.BceResponse
  1134. """
  1135. path = (b'/userId/%s/application/alarm/config/create' % compat.convert_to_bytes(user_id))
  1136. body = {
  1137. "userId": user_id,
  1138. "alarmDescription": alarm_description,
  1139. "appName": app_name,
  1140. "alarmName": alarm_name,
  1141. "monitorObjectType": monitor_object_type,
  1142. "monitorObject": monitor_object,
  1143. "srcName": src_name,
  1144. "srcType": src_type,
  1145. "type": type,
  1146. "level": level,
  1147. "actionEnabled": action_enabled,
  1148. "incidentActions": incident_actions,
  1149. "resumeActions": resume_actions,
  1150. "insufficientActions": insufficient_actions,
  1151. "insufficientCycle": insufficient_cycle,
  1152. "repeatAlarmCycle": repeat_alarm_cycle,
  1153. "maxRepeatCount": max_repeat_count,
  1154. "rules": rules
  1155. }
  1156. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
  1157. @required(rules=list)
  1158. def update_alarm_policy_for_application(self, user_id, alarm_description, alarm_name, app_name,
  1159. monitor_object_type, monitor_object, src_name, src_type, type, level,
  1160. rules, action_enabled=True, incident_actions=None, resume_actions=None,
  1161. insufficient_actions=None, insufficient_cycle=None, repeat_alarm_cycle=0,
  1162. max_repeat_count=0):
  1163. """
  1164. :param user_id:
  1165. :type user_id: string
  1166. :param alarm_description: alarm policy comment
  1167. :type alarm_description: string
  1168. :param alarm_name: unique alarm name in user_id
  1169. :type alarm_name: string
  1170. :param app_name: application name
  1171. :type app_name: string
  1172. :param monitor_object_type: monitor object type, enum: APP, SERVICE
  1173. :type monitor_object_type: string
  1174. :param monitor_object: application monitor object
  1175. :type monitor_object: bcm_model.ApplicationMonitorObject
  1176. :param src_name: task name
  1177. :type src_name: string
  1178. :param src_type: task type, enum: PROC,PORT,LOG,SCR
  1179. :type src_type: string
  1180. :param type: alarm type
  1181. :type type: string
  1182. :param level: alarm level
  1183. :type level: string
  1184. :param rules: list of application alarm rules
  1185. :type rules: list of ApplicationAlarmRule
  1186. :param action_enabled: is alarm action enabled
  1187. :type action_enabled: bool
  1188. :param incident_actions: The action to be taken in the alarm state
  1189. :type incident_actions: list of string
  1190. :param resume_actions: The action to be taken in the alarm resume
  1191. :type resume_actions: list of string
  1192. :param insufficient_actions:
  1193. :type insufficient_actions: list of string
  1194. :param insufficient_cycle: insufficient cycle
  1195. :type insufficient_cycle: int
  1196. :param repeat_alarm_cycle: repeat alarm_cycle
  1197. :type repeat_alarm_cycle: int
  1198. :param max_repeat_count: max repeat count
  1199. :type max_repeat_count: int
  1200. :return
  1201. :rtype baidubce.bce_response.BceResponse
  1202. """
  1203. path = (b'/userId/%s/application/alarm/config/update' % compat.convert_to_bytes(user_id))
  1204. body = {
  1205. "userId": user_id,
  1206. "alarmDescription": alarm_description,
  1207. "appName": app_name,
  1208. "alarmName": alarm_name,
  1209. "monitorObjectType": monitor_object_type,
  1210. "monitorObject": monitor_object,
  1211. "srcName": src_name,
  1212. "srcType": src_type,
  1213. "type": type,
  1214. "level": level,
  1215. "actionEnabled": action_enabled,
  1216. "incidentActions": incident_actions,
  1217. "resumeActions": resume_actions,
  1218. "insufficientActions": insufficient_actions,
  1219. "insufficientCycle": insufficient_cycle,
  1220. "repeatAlarmCycle": repeat_alarm_cycle,
  1221. "maxRepeatCount": max_repeat_count,
  1222. "rules": rules
  1223. }
  1224. return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body))
  1225. def create_dashboard(self, user_id=None, title=None, configure=None, dashboard_type=None, config=None):
  1226. """
  1227. Create a dashboard
  1228. :param user_id:
  1229. Master account ID
  1230. :type user_id: string
  1231. :param title:
  1232. Title of the dashboard
  1233. :type title: string
  1234. :param configure:
  1235. Configure the dashboard
  1236. :type configure:string
  1237. :param dashboard_type:
  1238. Dashboard type
  1239. :type dashboard_type:string
  1240. :param config:
  1241. :type config: baidubce.BceClientConfiguration
  1242. :return:
  1243. :rtype baidubce.bce_response.BceResponse
  1244. """
  1245. body = {
  1246. "userId": user_id,
  1247. "title": title,
  1248. "configure": configure,
  1249. "type": dashboard_type
  1250. }
  1251. user_id = compat.convert_to_bytes(user_id)
  1252. path = b'/dashboard/products/%s/dashboards' % user_id
  1253. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  1254. def get_dashboard(self, user_id=None, dashboard_name=None, config=None):
  1255. """
  1256. Create a dashboard
  1257. :param user_id:
  1258. Master account ID
  1259. :type user_id: string
  1260. :param dashboard_name:
  1261. Dashboard name
  1262. :type dashboard_name:string
  1263. :param config:
  1264. :type config: baidubce.BceClientConfiguration
  1265. :return:
  1266. :rtype baidubce.bce_response.BceResponse
  1267. """
  1268. if len(user_id) <= 0:
  1269. raise ValueError('user_id should not be none or empty string')
  1270. if len(dashboard_name) <= 0:
  1271. raise ValueError('dashboard_name should not be none or empty string')
  1272. user_id = compat.convert_to_bytes(user_id)
  1273. dashboard_name = compat.convert_to_bytes(dashboard_name)
  1274. path = b'/dashboard/products/%s/dashboards/%s' % (user_id, dashboard_name)
  1275. return self._send_csm_request(http_methods.GET, path, config=config)
  1276. def update_dashboard(self, user_id=None, title=None, configure=None,
  1277. dashboard_type=None, dashboard_name=None, config=None):
  1278. """
  1279. Create a dashboard
  1280. :param user_id:
  1281. Master account ID
  1282. :type user_id: string
  1283. :param title:
  1284. Title of the dashboard
  1285. :type title: string
  1286. :param configure:
  1287. Configure the dashboard
  1288. :type configure:string
  1289. :param dashboard_type:
  1290. Dashboard type
  1291. :type dashboard_type:string
  1292. :param dashboard_name:
  1293. Dashboard name
  1294. :type dashboard_name:string
  1295. :param config:
  1296. :type config: baidubce.BceClientConfiguration
  1297. :return:
  1298. :rtype baidubce.bce_response.BceResponse
  1299. """
  1300. if len(user_id) <= 0:
  1301. raise ValueError('user_id should not be none or empty string')
  1302. if len(dashboard_name) <= 0:
  1303. raise ValueError('dashboard_name should not be none or empty string')
  1304. body = {
  1305. "userId": user_id,
  1306. "title": title,
  1307. "configure": configure,
  1308. "type": dashboard_type
  1309. }
  1310. user_id = compat.convert_to_bytes(user_id)
  1311. dashboard_name = compat.convert_to_bytes(dashboard_name)
  1312. path = b'/dashboard/products/%s/dashboards/%s' % (user_id, dashboard_name)
  1313. return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
  1314. def delete_dashboard(self, user_id=None, dashboard_name=None, config=None):
  1315. """
  1316. Create a dashboard
  1317. :param user_id:
  1318. Master account ID
  1319. :type user_id: string
  1320. :param dashboard_name:
  1321. Dashboard name
  1322. :type dashboard_name:string
  1323. :param config:
  1324. :type config: baidubce.BceClientConfiguration
  1325. :return:
  1326. :rtype baidubce.bce_response.BceResponse
  1327. """
  1328. if len(user_id) <= 0:
  1329. raise ValueError('user_id should not be none or empty string')
  1330. if len(dashboard_name) <= 0:
  1331. raise ValueError('dashboard_name should not be none or empty string')
  1332. user_id = compat.convert_to_bytes(user_id)
  1333. dashboard_name = compat.convert_to_bytes(dashboard_name)
  1334. path = b'/dashboard/products/%s/dashboards/%s' % (user_id, dashboard_name)
  1335. return self._send_csm_request(http_methods.DELETE, path, config=config)
  1336. def duplicate_dashboard(self, user_id=None, dashboard_name=None, config=None):
  1337. """
  1338. Create a dashboard
  1339. :param user_id:
  1340. Master account ID
  1341. :type user_id: string
  1342. :param dashboard_name:
  1343. Dashboard name
  1344. :type dashboard_name:string
  1345. :param config:
  1346. :type config: baidubce.BceClientConfiguration
  1347. :return:
  1348. :rtype baidubce.bce_response.BceResponse
  1349. """
  1350. if len(user_id) <= 0:
  1351. raise ValueError('user_id should not be none or empty string')
  1352. if len(dashboard_name) <= 0:
  1353. raise ValueError('dashboard_name should not be none or empty string')
  1354. body = {
  1355. }
  1356. user_id = compat.convert_to_bytes(user_id)
  1357. dashboard_name = compat.convert_to_bytes(dashboard_name)
  1358. path = b'/dashboard/products/%s/dashboards/%s/duplicate' % (user_id, dashboard_name)
  1359. return self._send_csm_request(http_methods.POST, path, json.dumps(body), config=config)
  1360. def create_dashboard_widget(self, user_id=None, dashboard_name=None, config=None):
  1361. """
  1362. Create a dashboard
  1363. :param user_id:
  1364. Master account ID
  1365. :type user_id: string
  1366. :param dashboard_name:
  1367. Dashboard name
  1368. :type dashboard_name:string
  1369. :param config:
  1370. :type config: baidubce.BceClientConfiguration
  1371. :return:
  1372. :rtype baidubce.bce_response.BceResponse
  1373. """
  1374. if len(user_id) <= 0:
  1375. raise ValueError('user_id should not be none or empty string')
  1376. if len(dashboard_name) <= 0:
  1377. raise ValueError('dashboard_name should not be none or empty string')
  1378. body = {
  1379. }
  1380. user_id = compat.convert_to_bytes(user_id)
  1381. dashboard_name = compat.convert_to_bytes(dashboard_name)
  1382. path = b'/dashboard/products/%s/dashboards/%s/widgets' % (user_id, dashboard_name)
  1383. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  1384. def get_dashboard_widget(self, user_id=None, dashboard_name=None, widget_name=None, config=None):
  1385. """
  1386. Create a dashboard
  1387. :param user_id:
  1388. Master account ID
  1389. :type user_id: string
  1390. :param dashboard_name:
  1391. Dashboard name
  1392. :type dashboard_name:string
  1393. :param widget_name:
  1394. Widget name
  1395. :type widget_name:string
  1396. :param config:
  1397. :type config: baidubce.BceClientConfiguration
  1398. :return:
  1399. :rtype baidubce.bce_response.BceResponse
  1400. """
  1401. if len(user_id) <= 0:
  1402. raise ValueError('user_id should not be none or empty string')
  1403. if len(dashboard_name) <= 0:
  1404. raise ValueError('dashboard_name should not be none or empty string')
  1405. if len(widget_name) <= 0:
  1406. raise ValueError('widget_name should be none or empty string')
  1407. user_id = compat.convert_to_bytes(user_id)
  1408. dashboard_name = compat.convert_to_bytes(dashboard_name)
  1409. widget_name = compat.convert_to_bytes(widget_name)
  1410. path = b'/dashboard/products/%s/dashboards/%s/widgets/%s' % (user_id, dashboard_name, widget_name)
  1411. return self._send_csm_request(http_methods.GET, path, config=config)
  1412. def delete_dashboard_widget(self, user_id=None, dashboard_name=None, widget_name=None, config=None):
  1413. """
  1414. Create a dashboard
  1415. :param user_id:
  1416. Master account ID
  1417. :type user_id: string
  1418. :param dashboard_name:
  1419. Dashboard name
  1420. :type dashboard_name:string
  1421. :param widget_name:
  1422. Widget name
  1423. :type widget_name:string
  1424. :param config:
  1425. :type config: baidubce.BceClientConfiguration
  1426. :return:
  1427. :rtype baidubce.bce_response.BceResponse
  1428. """
  1429. if len(user_id) <= 0:
  1430. raise ValueError('user_id should not be none or empty string')
  1431. if len(dashboard_name) <= 0:
  1432. raise ValueError('dashboard_name should not be none or empty string')
  1433. if len(widget_name) <= 0:
  1434. raise ValueError('widget_name should be none or empty string')
  1435. user_id = compat.convert_to_bytes(user_id)
  1436. dashboard_name = compat.convert_to_bytes(dashboard_name)
  1437. widget_name = compat.convert_to_bytes(widget_name)
  1438. path = b'/dashboard/products/%s/dashboards/%s/widgets/%s' % (user_id, dashboard_name, widget_name)
  1439. return self._send_csm_request(http_methods.DELETE, path, config=config)
  1440. def duplicate_dashboard_widget(self, user_id=None, dashboard_name=None, widget_name=None, config=None):
  1441. """
  1442. Create a dashboard
  1443. :param user_id:
  1444. Master account ID
  1445. :type user_id: string
  1446. :param dashboard_name:
  1447. Dashboard name
  1448. :type dashboard_name:string
  1449. :param widget_name:
  1450. Widget name
  1451. :type widget_name:string
  1452. :param config:
  1453. :type config: baidubce.BceClientConfiguration
  1454. :return:
  1455. :rtype baidubce.bce_response.BceResponse
  1456. """
  1457. if len(user_id) <= 0:
  1458. raise ValueError('user_id should not be none or empty string')
  1459. if len(dashboard_name) <= 0:
  1460. raise ValueError('dashboard_name should not be none or empty string')
  1461. if len(widget_name) <= 0:
  1462. raise ValueError('widget_name should be none or empty string')
  1463. body = {
  1464. }
  1465. user_id = compat.convert_to_bytes(user_id)
  1466. dashboard_name = compat.convert_to_bytes(dashboard_name)
  1467. widget_name = compat.convert_to_bytes(widget_name)
  1468. path = (b'/dashboard/products/%s/dashboards/%s/widgets/%s/duplicate' %
  1469. (user_id, dashboard_name, widget_name))
  1470. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  1471. def update_dashboard_widget(self, user_id=None, dashboard_name=None, widget_name=None,
  1472. widget_type=None, title=None, configure=None, config=None):
  1473. """
  1474. Create a dashboard
  1475. :param user_id:
  1476. Master account ID
  1477. :type user_id: string
  1478. :param dashboard_name:
  1479. Dashboard name
  1480. :type dashboard_name:string
  1481. :param widget_name:
  1482. Widget name
  1483. :type widget_name:string
  1484. :param widget_type:
  1485. Widget type
  1486. :type widget_type:string
  1487. :param configure:
  1488. Widget configure
  1489. :type configure:object
  1490. :param config:
  1491. :type config: baidubce.BceClientConfiguration
  1492. :return:
  1493. :rtype baidubce.bce_response.BceResponse
  1494. """
  1495. if len(user_id) <= 0:
  1496. raise ValueError('user_id should not be none or empty string')
  1497. if len(dashboard_name) <= 0:
  1498. raise ValueError('dashboard_name should not be none or empty string')
  1499. if len(widget_name) <= 0:
  1500. raise ValueError('widget_name should be none or empty string')
  1501. body = {
  1502. "title": title,
  1503. "type": widget_type,
  1504. "configure": configure
  1505. }
  1506. user_id = compat.convert_to_bytes(user_id)
  1507. dashboard_name = compat.convert_to_bytes(dashboard_name)
  1508. widget_name = compat.convert_to_bytes(widget_name)
  1509. path = b'/dashboard/products/%s/dashboards/%s/widgets/%s' % (user_id, dashboard_name, widget_name)
  1510. return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
  1511. def get_dashboard_report_data(self, data=None, time=None, config=None):
  1512. """
  1513. Get dashboard report data
  1514. :param data:
  1515. Query data
  1516. :type data: object
  1517. :param time:
  1518. Query data time
  1519. :type time: string
  1520. :param config:
  1521. :type config: baidubce.BceClientConfiguration
  1522. :return:
  1523. :rtype baidubce.bce_response.BceResponse
  1524. """
  1525. body = {
  1526. "data": data,
  1527. "time": time
  1528. }
  1529. path = b'/dashboard/metric/report'
  1530. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  1531. def get_dashboard_trend_data(self, data=None, time=None, config=None):
  1532. """
  1533. Get dashboard report data
  1534. :param data:
  1535. Query data
  1536. :type data: object
  1537. :param time:
  1538. Query data time
  1539. :type time: string
  1540. :param config:
  1541. :type config: baidubce.BceClientConfiguration
  1542. :return:
  1543. :rtype baidubce.bce_response.BceResponse
  1544. """
  1545. body = {
  1546. "data": data,
  1547. "time": time
  1548. }
  1549. path = b'/dashboard/metric/trend'
  1550. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  1551. def get_dashboard_gauge_chart_data(self, data=None, time=None, config=None):
  1552. """
  1553. Get dashboard report data
  1554. :param data:
  1555. Query data
  1556. :type data: object
  1557. :param time:
  1558. Query data time
  1559. :type time: string
  1560. :param config:
  1561. :type config: baidubce.BceClientConfiguration
  1562. :return:
  1563. :rtype baidubce.bce_response.BceResponse
  1564. """
  1565. body = {
  1566. "data": data,
  1567. "time": time
  1568. }
  1569. path = b'/dashboard/metric/gaugechart'
  1570. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  1571. def get_dashboard_billboard_data(self, data=None, time=None, config=None):
  1572. """
  1573. Get dashboard report data
  1574. :param data:
  1575. Query data
  1576. :type data: object
  1577. :param time:
  1578. Query data time
  1579. :type time: string
  1580. :param config:
  1581. :type config: baidubce.BceClientConfiguration
  1582. :return:
  1583. :rtype baidubce.bce_response.BceResponse
  1584. """
  1585. body = {
  1586. "data": data,
  1587. "time": time
  1588. }
  1589. path = b'/dashboard/metric/billboard'
  1590. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  1591. def get_dashboard_trend_senior_data(self, data=None, time=None, config=None):
  1592. """
  1593. Get dashboard report data
  1594. :param data:
  1595. Query data
  1596. :type data: object
  1597. :param time:
  1598. Query data time
  1599. :type time: string
  1600. :param config:
  1601. :type config: baidubce.BceClientConfiguration
  1602. :return:
  1603. :rtype baidubce.bce_response.BceResponse
  1604. """
  1605. body = {
  1606. "data": data,
  1607. "time": time
  1608. }
  1609. path = b'/dashboard/metric/trend/senior'
  1610. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  1611. def get_dashboard_dimensions(self, user_id, metric_name, region, service, show_id,
  1612. dimensions=None, config=None):
  1613. """
  1614. Get dashboard dimensions
  1615. :param user_id:
  1616. Master account ID
  1617. :type user_id: string
  1618. :param dimensions:
  1619. dashboard dimensions
  1620. :type dimensions: string
  1621. :param metric_name:
  1622. dashboard metric_name
  1623. :type metric_name: string
  1624. :param region:
  1625. dashboard dimensions region
  1626. :type region: string
  1627. :param service:
  1628. cloud service
  1629. :type service:
  1630. :param show_id:
  1631. cloud resourceId
  1632. :type show_id:
  1633. :param config:
  1634. :type config: baidubce.BceClientConfiguration
  1635. :return:
  1636. :rtype baidubce.bce_response.BceResponse
  1637. """
  1638. if len(user_id) <= 0:
  1639. raise ValueError('user_id should not be none or empty string')
  1640. if len(metric_name) <= 0:
  1641. raise ValueError('metric_name should not be none or empty string')
  1642. if len(region) <= 0:
  1643. raise ValueError('region should not be none or empty string')
  1644. if len(service) <= 0:
  1645. raise ValueError('service should not be none or empty string')
  1646. if len(show_id) <= 0:
  1647. raise ValueError('show_id should not be none or empty string')
  1648. params = {
  1649. b'dimensions': dimensions,
  1650. b'userId': user_id,
  1651. b'metricName': metric_name,
  1652. b'region': region,
  1653. b'service': service,
  1654. b'showId': show_id,
  1655. }
  1656. user_id = compat.convert_to_bytes(user_id)
  1657. service = compat.convert_to_bytes(service)
  1658. region = compat.convert_to_bytes(region)
  1659. path = b'/userId/%s/services/%s/region/%s/metric/dimensions' % (user_id, service, region)
  1660. return self._send_csm_request(http_methods.GET, path, params=params, config=config)
  1661. def create_application_data(self, name, type, user_id, alias=None, description=None, config=None):
  1662. """
  1663. create application data
  1664. :param name:
  1665. :param type:
  1666. :param user_id:
  1667. :param alias:
  1668. :param description:
  1669. :param config:
  1670. :return:
  1671. :rtype baidubce.bce_response.BceResponse
  1672. """
  1673. if len(user_id) <= 0:
  1674. raise ValueError("user_id should not be null")
  1675. if len(type) <= 0:
  1676. raise ValueError("type should not be null")
  1677. if len(name) <= 0:
  1678. raise ValueError("name should not be null")
  1679. req = {
  1680. "name": name,
  1681. "type": type,
  1682. "userId": user_id,
  1683. }
  1684. if alias is not None:
  1685. req["alias"] = alias
  1686. if description is not None:
  1687. req["description"] = description
  1688. user_id = compat.convert_to_bytes(user_id)
  1689. path = b'/userId/%s/application' % user_id
  1690. return self._send_csm_request(http_methods.POST, path, body=json.dumps(req), config=config)
  1691. def get_application_data_list(self, user_id, page_no=None, page_size=None, search_name=None, config=None):
  1692. """
  1693. get_application_data_list
  1694. :param user_id:
  1695. :param page_no:
  1696. :param page_size:
  1697. :param search_name:
  1698. :param config:
  1699. :return:
  1700. :rtype baidubce.bce_response.BceResponse
  1701. """
  1702. if len(user_id) <= 0:
  1703. raise ValueError("user_id should not be null")
  1704. if page_no is None:
  1705. page_no = 1
  1706. if page_size is None:
  1707. page_size = 10
  1708. user_id = compat.convert_to_bytes(user_id)
  1709. path = b'/userId/%s/application' % user_id
  1710. params = {
  1711. b'pageSize': page_size,
  1712. b'pageNo': page_no,
  1713. }
  1714. if search_name is not None:
  1715. params[b'searchName'] = search_name
  1716. return self._send_request(http_methods.GET, path, params=params, config=config)
  1717. def update_application_data(self, user_id, id, name, type, alias=None, description=None, config=None):
  1718. """
  1719. update_application_data
  1720. :param user_id:
  1721. :param id:
  1722. :param name:
  1723. :param type:
  1724. :param alias:
  1725. :param description:
  1726. :param config:
  1727. :return:
  1728. """
  1729. if len(user_id) <= 0:
  1730. raise ValueError("user_id should not be null")
  1731. if len(type) <= 0:
  1732. raise ValueError("type should not be null")
  1733. if len(name) <= 0:
  1734. raise ValueError("name should not be null")
  1735. if len(id) <= 0:
  1736. raise ValueError("id should not be null")
  1737. req = {
  1738. "userId": user_id,
  1739. "id": id,
  1740. "name": name,
  1741. "type": type
  1742. }
  1743. if alias is not None:
  1744. req["alias"] = alias
  1745. if description is not None:
  1746. req["description"] = description
  1747. user_id = compat.convert_to_bytes(user_id)
  1748. path = b'/userId/%s/application' % user_id
  1749. return self._send_csm_request(http_methods.PUT, path, body=json.dumps(req), config=config)
  1750. def delete_application_data(self, user_id, name, config=None):
  1751. """
  1752. delete_application_data
  1753. :param user_id:
  1754. :param name:
  1755. :param config:
  1756. :return:
  1757. """
  1758. if len(user_id) <= 0:
  1759. raise ValueError("user_id should not be null")
  1760. if len(name) <= 0:
  1761. raise ValueError("name should null be null")
  1762. req = {
  1763. "name": name
  1764. }
  1765. user_id = compat.convert_to_bytes(user_id)
  1766. path = b'/userId/%s/application' % user_id
  1767. return self._send_csm_request(http_methods.DELETE, path, body=json.dumps(req), config=config)
  1768. def get_application_instance_list(self, user_id, region, app_name, search_name, page_no=None, page_size=None,
  1769. search_value=None, config=None):
  1770. """
  1771. get_application_instance_list
  1772. :param user_id:
  1773. :param region:
  1774. :param app_name:
  1775. :param search_name:
  1776. :param page_no:
  1777. :param page_size:
  1778. :param search_value:
  1779. :param config:
  1780. :return:
  1781. :rtype baidubce.bce_response.BceResponse
  1782. """
  1783. if len(user_id) <= 0:
  1784. raise ValueError("user_id should not be null")
  1785. if len(region) <= 0:
  1786. raise ValueError("region should not be null")
  1787. if len(app_name) <= 0:
  1788. raise ValueError("app_name should not be null")
  1789. if page_no is None:
  1790. page_no = 1
  1791. if page_size is None:
  1792. page_size = 10
  1793. user_id = compat.convert_to_bytes(user_id)
  1794. path = b'/userId/%s/instances/all' % user_id
  1795. req = {
  1796. "appName": app_name,
  1797. "region": region,
  1798. "pageNo": page_no,
  1799. "pageSize": page_size,
  1800. "searchName": search_name
  1801. }
  1802. if search_value is not None:
  1803. req["searchValue"] = search_value
  1804. return self._send_csm_request(http_methods.POST, path, body=json.dumps(req), config=config)
  1805. @required(user_id=value_type,
  1806. app_name=value_type,
  1807. host_list=list)
  1808. def create_application_instance(self, user_id, app_name, host_list, config=None):
  1809. """
  1810. create_application_instance
  1811. :param user_id:
  1812. :param app_name:
  1813. :param host_list:
  1814. :param config:
  1815. :return:
  1816. :rtype baidubce.bce_response.BceResponse
  1817. """
  1818. if len(user_id) <= 0:
  1819. raise ValueError("user_id should not be null")
  1820. if len(app_name) <= 0:
  1821. raise ValueError("app_name should not be null")
  1822. if len(host_list) <= 0:
  1823. raise ValueError("host_list should not be null")
  1824. host_list_json = []
  1825. for host in host_list:
  1826. host_list_json.append(host)
  1827. req = {
  1828. "appName": app_name,
  1829. "userId": user_id,
  1830. "hostList": host_list_json
  1831. }
  1832. user_id = compat.convert_to_bytes(user_id)
  1833. path = b'/userId/%s/application/instance/bind' % user_id
  1834. return self._send_csm_request(http_methods.POST, path, body=json.dumps(req), config=config)
  1835. def get_application_instance_created_list(self, user_id, app_name, region=None, config=None):
  1836. """
  1837. get_application_instance_created_list
  1838. :param user_id:
  1839. :param app_name:
  1840. :param region:
  1841. :param config:
  1842. :return:
  1843. """
  1844. if len(user_id) <= 0:
  1845. raise ValueError("user_id should not be null")
  1846. if len(app_name) <= 0:
  1847. raise ValueError("app_name should not be null")
  1848. user_id = compat.convert_to_bytes(user_id)
  1849. app_name = compat.convert_to_bytes(app_name)
  1850. path = b'/userId/%s/application/%s/instance/list' % (user_id, app_name)
  1851. params = None
  1852. if region is not None:
  1853. params = {
  1854. 'region': region
  1855. }
  1856. return self._send_csm_request(http_methods.GET, path, params=params, config=config)
  1857. def delete_application_instance(self, user_id, app_name, id, config=None):
  1858. """
  1859. delete_application_instance
  1860. :param user_id:
  1861. :param app_name:
  1862. :param id:
  1863. :param config:
  1864. :return:
  1865. """
  1866. if len(user_id) <= 0:
  1867. raise ValueError("user_id should not be null")
  1868. if len(app_name) <= 0:
  1869. raise ValueError("app_name should not be null")
  1870. if len(id) <= 0:
  1871. raise ValueError("id should not be null")
  1872. user_id = compat.convert_to_bytes(user_id)
  1873. path = b'/userId/%s/application/instance' % user_id
  1874. req = {
  1875. "id": id,
  1876. "appName": app_name
  1877. }
  1878. return self._send_csm_request(http_methods.DELETE, path, body=json.dumps(req), config=config)
  1879. @required(user_id=value_type, app_name=value_type, alias_name=value_type, type=int,
  1880. target=value_type, cycle=int, description=value_type, log_example=value_type,
  1881. match_rule=value_type, rate=int, extract_result=list, metrics=list)
  1882. def create_application_instance_task(self, user_id, app_name, alias_name, type, target,
  1883. cycle=None, description=None, log_example=None, match_rule=None, rate=None,
  1884. extract_result=None, metrics=None, config=None):
  1885. """
  1886. create_application_instance_task
  1887. :param user_id:
  1888. :param app_name:
  1889. :param alias_name:
  1890. :param type:
  1891. :param target:
  1892. :param cycle:
  1893. :param description:
  1894. :param log_example:
  1895. :param match_rule:
  1896. :param rate:
  1897. :param extract_result:
  1898. :param metrics:
  1899. :param config:
  1900. :return:
  1901. :rtype baidubce.bce_response.BceResponse
  1902. """
  1903. if len(user_id) <= 0:
  1904. raise ValueError("user_id should not be null")
  1905. if len(app_name) <= 0:
  1906. raise ValueError("app_name should not be null")
  1907. if type is None:
  1908. raise ValueError("type should not be null")
  1909. if len(alias_name) <= 0:
  1910. raise ValueError("alias_name should not be null")
  1911. if len(target) <= 0:
  1912. raise ValueError("target should not be null")
  1913. if cycle is None:
  1914. cycle = 60
  1915. req = {
  1916. "appName": app_name,
  1917. "type": str(type),
  1918. "aliasName": alias_name,
  1919. "target": target,
  1920. "cycle": str(cycle)
  1921. }
  1922. if description is not None:
  1923. req["description"] = description
  1924. if str(type) == "2":
  1925. if log_example is None:
  1926. raise ValueError("log_example should not be null")
  1927. if match_rule is None:
  1928. raise ValueError("match_rule should not be null")
  1929. if rate is None:
  1930. raise ValueError("rate should not be null")
  1931. if extract_result is None:
  1932. raise ValueError("extract_result should not be null")
  1933. if metrics is None:
  1934. raise ValueError("metrics should not be null")
  1935. req["logExample"] = log_example
  1936. req["matchRule"] = match_rule
  1937. req["rate"] = rate
  1938. extract_result_json = []
  1939. for result in extract_result:
  1940. extract_result_json.append(result)
  1941. req["extractResult"] = extract_result_json
  1942. metrics_json = []
  1943. for metric in metrics:
  1944. metrics_json.append(metric)
  1945. req["metrics"] = metrics_json
  1946. user_id = compat.convert_to_bytes(user_id)
  1947. path = b'/userId/%s/application/task/create' % user_id
  1948. return self._send_csm_request(http_methods.POST, path, body=json.dumps(req), config=config)
  1949. def get_application_monitor_task_detail(self, user_id, app_name, task_name, config=None):
  1950. """
  1951. get_application_monitor_task_detail
  1952. :param user_id:
  1953. :param app_name:
  1954. :param task_name:
  1955. :param config:
  1956. :return:
  1957. :rtype baidubce.bce_response.BceResponse
  1958. """
  1959. if len(user_id) <= 0:
  1960. raise ValueError("user_id should not be null")
  1961. if len(app_name) <= 0:
  1962. raise ValueError("app_name should not be null")
  1963. if len(task_name) <= 0:
  1964. raise ValueError("task_name should not be null")
  1965. user_id = compat.convert_to_bytes(user_id)
  1966. app_name = compat.convert_to_bytes(app_name)
  1967. task_name = compat.convert_to_bytes(task_name)
  1968. path = b'/userId/%s/application/%s/task/%s' % (user_id, app_name, task_name)
  1969. return self._send_csm_request(http_methods.GET, path, config=config)
  1970. def get_application_monitor_task_list(self, user_id, app_name, type=None, config=None):
  1971. """
  1972. get_application_monitor_task_list
  1973. :param user_id:
  1974. :param app_name:
  1975. :param type:
  1976. :param config:
  1977. :return:
  1978. """
  1979. if len(user_id) <= 0:
  1980. raise ValueError("user_id should not be null")
  1981. if len(app_name) <= 0:
  1982. raise ValueError("app_name should not be null")
  1983. user_id = compat.convert_to_bytes(user_id)
  1984. app_name = compat.convert_to_bytes(app_name)
  1985. path = b'/userId/%s/application/%s/task/list' % (user_id, app_name)
  1986. params = None
  1987. if type is not None:
  1988. params = {
  1989. 'type': type
  1990. }
  1991. return self._send_csm_request(http_methods.GET, path, params=params, config=config,
  1992. body_parser=bcm_handler.parse_json_list)
  1993. @required(user_id=value_type, app_name=value_type, name=value_type, alias_name=value_type, type=int,
  1994. target=value_type, cycle=int, description=value_type, log_example=value_type,
  1995. match_rule=value_type, rate=int, extract_result=list, metrics=list)
  1996. def update_application_monitor_task(self, user_id, app_name, alias_name, name, type, target,
  1997. cycle=None, description=None, log_example=None, match_rule=None, rate=None,
  1998. extract_result=None, metrics=None, config=None):
  1999. """
  2000. update application monitor task
  2001. :param user_id:
  2002. :param app_name:
  2003. :param alias_name:
  2004. :param name:
  2005. :param type:
  2006. :param target:
  2007. :param cycle:
  2008. :param description:
  2009. :param log_example:
  2010. :param match_rule:
  2011. :param rate:
  2012. :param extract_result:
  2013. :param metrics:
  2014. :param config:
  2015. :return:
  2016. :rtype baidubce.bce_response.BceResponse
  2017. """
  2018. if len(user_id) <= 0:
  2019. raise ValueError("user_id should not be null")
  2020. if len(app_name) <= 0:
  2021. raise ValueError("app_name should not be null")
  2022. if len(name) <= 0:
  2023. raise ValueError("name should not be null")
  2024. if type is None:
  2025. raise ValueError("type should not be null")
  2026. if len(alias_name) <= 0:
  2027. raise ValueError("alias_name should not be null")
  2028. if len(target) <= 0:
  2029. raise ValueError("target should not be null")
  2030. req = {
  2031. "appName": app_name,
  2032. "name": name,
  2033. "type": str(type),
  2034. "aliasName": alias_name,
  2035. "target": target,
  2036. }
  2037. if cycle is not None:
  2038. req["cycle"] = cycle
  2039. if description is not None:
  2040. req["description"] = description
  2041. if str(type) == "2":
  2042. if log_example is None:
  2043. raise ValueError("log_example should not be null")
  2044. if match_rule is None:
  2045. raise ValueError("match_rule should not be null")
  2046. if rate is None:
  2047. raise ValueError("rate should not be null")
  2048. if extract_result is None:
  2049. raise ValueError("extract_result should not be null")
  2050. if metrics is None:
  2051. raise ValueError("metrics should not be null")
  2052. req["logExample"] = log_example
  2053. req["matchRule"] = match_rule
  2054. req["rate"] = rate
  2055. extract_result_json = []
  2056. for result in extract_result:
  2057. extract_result_json.append(result)
  2058. req["extractResult"] = extract_result_json
  2059. metrics_json = []
  2060. for metric in metrics:
  2061. metrics_json.append(metric)
  2062. req["metrics"] = metrics_json
  2063. user_id = compat.convert_to_bytes(user_id)
  2064. path = b'/userId/%s/application/task/update' % user_id
  2065. return self._send_csm_request(http_methods.PUT, path, body=json.dumps(req), config=config)
  2066. def delete_application_monitor_task(self, user_id, name, app_name, config=None):
  2067. """
  2068. delete_application_monitor_task
  2069. :param user_id:
  2070. :param name:
  2071. :param app_name:
  2072. :param config:
  2073. :return:
  2074. :rtype baidubce.bce_response.BceResponse
  2075. """
  2076. if len(user_id) <= 0:
  2077. raise ValueError("user_id should not be null")
  2078. if len(app_name) <= 0:
  2079. raise ValueError("app_name should not be null")
  2080. if len(name) <= 0:
  2081. raise ValueError("name should not be null")
  2082. user_id = compat.convert_to_bytes(user_id)
  2083. path = b'/userId/%s/application/task/delete' % user_id
  2084. req = {
  2085. "name": name,
  2086. "appName": app_name
  2087. }
  2088. return self._send_csm_request(http_methods.DELETE, path, body=json.dumps(req), config=config)
  2089. def create_application_dimension_table(self, user_id, app_name, table_name, map_content_json, config=None):
  2090. """
  2091. create_application_dimension_table
  2092. :param user_id:
  2093. :param app_name:
  2094. :param table_name:
  2095. :param map_content_json:
  2096. :param config:
  2097. :return:
  2098. :rtype baidubce.bce_response.BceResponse
  2099. """
  2100. if len(user_id) <= 0:
  2101. raise ValueError("user_id should not be null")
  2102. if len(app_name) <= 0:
  2103. raise ValueError("app_name should not be null")
  2104. if len(table_name) <= 0:
  2105. raise ValueError("table_name should not be null")
  2106. if len(map_content_json) <= 0:
  2107. raise ValueError("map_content_json should not be null")
  2108. req = {
  2109. "userId": user_id,
  2110. "appName": app_name,
  2111. "tableName": table_name,
  2112. "mapContentJson": map_content_json
  2113. }
  2114. user_id = compat.convert_to_bytes(user_id)
  2115. path = b'/userId/%s/application/dimensionMap/create' % user_id
  2116. return self._send_csm_request(http_methods.POST, path, body=json.dumps(req), config=config)
  2117. def get_application_dimension_table_list(self, user_id, app_name, search_name=None, config=None):
  2118. """
  2119. get_application_dimension_table_list
  2120. :param user_id:
  2121. :param app_name:
  2122. :param search_name:
  2123. :param config:
  2124. :return:
  2125. :rtype baidubce.bce_response.BceResponse
  2126. """
  2127. if len(user_id) <= 0:
  2128. raise ValueError("user_id should not be null")
  2129. if len(app_name) <= 0:
  2130. raise ValueError("app_name should not be null")
  2131. user_id = compat.convert_to_bytes(user_id)
  2132. app_name = compat.convert_to_bytes(app_name)
  2133. path = b'/userId/%s/application/%s/dimensionMap/list' % (user_id, app_name)
  2134. params = None
  2135. if search_name is not None:
  2136. params = {
  2137. 'searchName': search_name
  2138. }
  2139. return self._send_csm_request(http_methods.GET, path, params=params, config=config)
  2140. def update_application_dimension_table(self, user_id, app_name, table_name, map_content_json, config=None):
  2141. """
  2142. update_application_dimension_table
  2143. :param user_id:
  2144. :param app_name:
  2145. :param table_name:
  2146. :param map_content_json:
  2147. :param config:
  2148. :return:
  2149. :rtype baidubce.bce_response.BceResponse
  2150. """
  2151. if len(user_id) <= 0:
  2152. raise ValueError("user_id should not be null")
  2153. if len(app_name) <= 0:
  2154. raise ValueError("app_name should not be null")
  2155. if len(table_name) <= 0:
  2156. raise ValueError("table_name should not be null")
  2157. if len(map_content_json) <= 0:
  2158. raise ValueError("map_content_json should not be null")
  2159. req = {
  2160. "userId": user_id,
  2161. "appName": app_name,
  2162. "tableName": table_name,
  2163. "mapContentJson": map_content_json
  2164. }
  2165. user_id = compat.convert_to_bytes(user_id)
  2166. path = b'/userId/%s/application/dimensionMap/update' % user_id
  2167. return self._send_csm_request(http_methods.PUT, path, body=json.dumps(req), config=config)
  2168. def delete_application_dimension_table(self, user_id, app_name, table_name, config=None):
  2169. """
  2170. delete_application_dimension_table
  2171. :param user_id:
  2172. :param app_name:
  2173. :param table_name:
  2174. :param config:
  2175. :return:
  2176. :rtype baidubce.bce_response.BceResponse
  2177. """
  2178. if len(user_id) <= 0:
  2179. raise ValueError("user_id should not be null")
  2180. if len(app_name) <= 0:
  2181. raise ValueError("app_name should not be null")
  2182. if len(table_name) <= 0:
  2183. raise ValueError("table_name should not be null")
  2184. req = {
  2185. "userId": user_id,
  2186. "appName": app_name,
  2187. "tableName": table_name
  2188. }
  2189. user_id = compat.convert_to_bytes(user_id)
  2190. path = b'/userId/%s/application/dimensionMap/delete' % user_id
  2191. return self._send_csm_request(http_methods.DELETE, path, body=json.dumps(req), config=config)
  2192. @required(page_no=int, page_size=int, account_id=str, start_time=str, end_time=str)
  2193. def get_cloud_event_data(self, page_no=1, page_size=10, start_time=None, end_time=None, account_id=None,
  2194. ascending=None, scope=None, region=None, event_level=None, event_name=None,
  2195. event_alias=None, resource_type=None, resource_id=None, event_id=None):
  2196. """
  2197. :param page_no: page number
  2198. :type page_no: int
  2199. :param page_size: page size
  2200. :type page_size: int
  2201. :param start_time: start time, such as 2023-12-05T09:54:15Z
  2202. :type start_time: string
  2203. :param end_time: end time, such as 2023-12-05T09:54:15Z
  2204. :type end_time: string
  2205. :param account_id: account id
  2206. :type account_id: string
  2207. :param ascending: ascending
  2208. :type ascending: bool
  2209. :param scope: scope
  2210. :type scope: string
  2211. :param region: region
  2212. :type region: string
  2213. :param event_level: event level
  2214. :type event_level: None or ENUM {'NOTICE', 'WARNING', 'MAJOR', 'CRITICAL'}
  2215. :param event_name: event name
  2216. :type event_name: string
  2217. :param event_alias: event alias
  2218. :type event_alias: string
  2219. :param resource_type: resource type
  2220. :type resource_type: string
  2221. :param resource_id: resource id
  2222. :type resource_id: string
  2223. :param event_id: event id
  2224. :type event_id: string
  2225. :return
  2226. :rtype baidubce.bce_response.BceResponse
  2227. """
  2228. path = b'/bce-event/list'
  2229. params = {
  2230. b'pageNo': page_no,
  2231. b'pageSize': page_size,
  2232. b'startTime': start_time,
  2233. b'endTime': end_time,
  2234. b'accountId': account_id,
  2235. b'ascending': ascending,
  2236. b'scope': scope,
  2237. b'region': region,
  2238. b'eventLevel': event_level,
  2239. b'eventName': event_name,
  2240. b'eventAlias': event_alias,
  2241. b'resourceType': resource_type,
  2242. b'resourceId': resource_id,
  2243. b'eventId': event_id,
  2244. }
  2245. return self._send_event_request(http_methods.GET, path, params=params)
  2246. @required(page_no=int, page_size=int, account_id=str, start_time=str, end_time=str)
  2247. def get_platform_event_data(self, page_no=1, page_size=10, start_time=None, end_time=None, account_id=None,
  2248. ascending=None, scope=None, region=None, event_level=None, event_name=None,
  2249. event_alias=None, event_id=None):
  2250. """
  2251. :param page_no: page number
  2252. :type page_no: int
  2253. :param page_size: page size
  2254. :type page_size: int
  2255. :param start_time: start time, such as 2023-12-05T09:54:15Z
  2256. :type start_time: string
  2257. :param end_time: end time, such as 2023-12-05T09:54:15Z
  2258. :type end_time: string
  2259. :param account_id: account id
  2260. :type account_id: string
  2261. :param ascending: ascending
  2262. :type ascending: bool
  2263. :param scope: scope
  2264. :type scope: string
  2265. :param region: region
  2266. :type region: string
  2267. :param event_level: event level
  2268. :type event_level: None or ENUM {'NOTICE', 'WARNING', 'MAJOR', 'CRITICAL'}
  2269. :param event_name: event name
  2270. :type event_name: string
  2271. :param event_alias: event alias
  2272. :type event_alias: string
  2273. :param event_id: event id
  2274. :type event_id: string
  2275. :return
  2276. :rtype baidubce.bce_response.BceResponse
  2277. """
  2278. path = b'/platform-event/list'
  2279. params = {
  2280. b'pageNo': page_no,
  2281. b'pageSize': page_size,
  2282. b'startTime': start_time,
  2283. b'endTime': end_time,
  2284. b'accountId': account_id,
  2285. b'ascending': ascending,
  2286. b'scope': scope,
  2287. b'region': region,
  2288. b'eventLevel': event_level,
  2289. b'eventName': event_name,
  2290. b'eventAlias': event_alias,
  2291. b'eventId': event_id,
  2292. }
  2293. return self._send_event_request(http_methods.GET, path, params=params)
  2294. @required(account_id=str, service_name=str, name=str, block_status=str, incident_actions=list)
  2295. def create_event_policy(self, account_id, service_name, name, block_status, event_filter,
  2296. resource, incident_actions):
  2297. """
  2298. :param account_id: account id
  2299. :type account_id: string
  2300. :param service_name: service name
  2301. :type service_name: string
  2302. :param name: event policy name
  2303. :type name: string
  2304. :param block_status: block status, enum: NORMAL, BLOCKED
  2305. :type block_status: string
  2306. :param event_filter: event filter
  2307. :type event_filter: EventFilter
  2308. :param resource: resource filter
  2309. :type resource: EventResourceFilter
  2310. :param incident_actions: incident actions
  2311. :type incident_actions: list of string
  2312. """
  2313. if event_filter is None:
  2314. raise ValueError('event_filter should not be none')
  2315. if resource is None:
  2316. raise ValueError('resource should not be none')
  2317. path = b'/accounts/%s/services/%s/alarm-policies' % (compat.convert_to_bytes(account_id),
  2318. compat.convert_to_bytes(service_name))
  2319. body = {
  2320. "account_id": account_id,
  2321. "service_name": service_name,
  2322. "name": name,
  2323. "blockStatus": block_status,
  2324. "eventFilter": event_filter,
  2325. "resource": resource,
  2326. "incidentActions": incident_actions
  2327. }
  2328. return self._send_event_request(http_methods.POST, path, body=json.dumps(body))
  2329. @required(user_id=str, region=str, service_name=str, type_name=str, name=str)
  2330. def create_instance_group(self, user_id, region, service_name, type_name, name, resource_id_list):
  2331. """
  2332. :param user_id: user id
  2333. :type user_id: string
  2334. :param region: region
  2335. :type region: string
  2336. :param service_name: service name
  2337. :type service_name: string
  2338. :param type_name: type name
  2339. :type type_name: string
  2340. :param name: instance group name
  2341. :type name: string
  2342. :param resource_id_list: resource id list
  2343. :type resource_id_list: list of MonitorResource
  2344. """
  2345. path = b'/userId/%s/instance-group' % compat.convert_to_bytes(user_id)
  2346. body = {
  2347. "userId": user_id,
  2348. "region": region,
  2349. "serviceName": service_name,
  2350. "typeName": type_name,
  2351. "name": name,
  2352. "resourceIdList": resource_id_list
  2353. }
  2354. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
  2355. @required(user_id=str, ig_id=str, region=str, service_name=str, type_name=str, name=str)
  2356. def update_instance_group(self, ig_id, user_id, region, service_name, type_name, name):
  2357. """
  2358. :param ig_id: instance group id
  2359. :type ig_id: string
  2360. :param user_id: user id
  2361. :type user_id: string
  2362. :param region: region
  2363. :type region: string
  2364. :param service_name: service name
  2365. :type service_name: string
  2366. :param type_name: type name
  2367. :type type_name: string
  2368. :param name: instance group name
  2369. :type name: string
  2370. """
  2371. path = b'/userId/%s/instance-group' % compat.convert_to_bytes(user_id)
  2372. body = {
  2373. "id": ig_id,
  2374. "userId": user_id,
  2375. "region": region,
  2376. "serviceName": service_name,
  2377. "typeName": type_name,
  2378. "name": name,
  2379. }
  2380. return self._send_csm_request(http_methods.PATCH, path, body=json.dumps(body))
  2381. @required(user_id=str, ig_id=str)
  2382. def delete_instance_group(self, user_id, ig_id):
  2383. """
  2384. :param user_id: user id
  2385. :type user_id: string
  2386. :param ig_id: instance group id
  2387. :type ig_id: string
  2388. """
  2389. path = b'/userId/%s/instance-group/%s' % (compat.convert_to_bytes(user_id), compat.convert_to_bytes(ig_id))
  2390. return self._send_csm_request(http_methods.DELETE, path)
  2391. @required(user_id=str, ig_id=str)
  2392. def get_instance_group(self, user_id, ig_id):
  2393. """
  2394. :param user_id: user id
  2395. :type user_id: string
  2396. :param ig_id: instance group id
  2397. :type ig_id: string
  2398. """
  2399. path = b'/userId/%s/instance-group/%s' % (compat.convert_to_bytes(user_id), compat.convert_to_bytes(ig_id))
  2400. return self._send_csm_request(http_methods.GET, path)
  2401. @required(user_id=str, page_no=int, page_size=int)
  2402. def list_instance_group(self, user_id, name, service_name, region, type_name, page_no, page_size):
  2403. """
  2404. :param user_id: user id
  2405. :type user_id: string
  2406. :param name: instance group name
  2407. :type name: string
  2408. :param service_name: service name
  2409. :type service_name: string
  2410. :param region: region
  2411. :type region: string
  2412. :param type_name: type name
  2413. :type type_name: string
  2414. :param page_no: page number
  2415. :type page_no: int
  2416. :param page_size: page size
  2417. :type page_size: int
  2418. """
  2419. path = b'/userId/%s/instance-group/list' % compat.convert_to_bytes(user_id)
  2420. params = {
  2421. b"userId": user_id,
  2422. b"name": name,
  2423. b"serviceName": service_name,
  2424. b"region": region,
  2425. b"typeName": type_name,
  2426. b"pageNo": page_no,
  2427. b"pageSize": page_size
  2428. }
  2429. return self._send_csm_request(http_methods.GET, path, params=params)
  2430. @required(user_id=str, ig_id=str, resource_id_list=list)
  2431. def add_ig_instance(self, ig_id, user_id, resource_id_list):
  2432. """
  2433. :param ig_id: instance group id
  2434. :type ig_id: string
  2435. :param user_id: user id
  2436. :type user_id: string
  2437. :param resource_id_list: resource id list
  2438. :type resource_id_list: list of MonitorResource
  2439. """
  2440. path = b'/userId/%s/instance-group/%s/instance/add' % (compat.convert_to_bytes(user_id),
  2441. compat.convert_to_bytes(ig_id))
  2442. body = {
  2443. "id": ig_id,
  2444. "userId": user_id,
  2445. "resourceIdList": resource_id_list
  2446. }
  2447. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
  2448. @required(user_id=str, ig_id=str, resource_id_list=list)
  2449. def remove_ig_instance(self, ig_id, user_id, resource_id_list):
  2450. """
  2451. :param ig_id: instance group id
  2452. :type ig_id: string
  2453. :param user_id: user id
  2454. :type user_id: string
  2455. :param resource_id_list: resource id list
  2456. :type resource_id_list: list of MonitorResource
  2457. """
  2458. path = b'/userId/%s/instance-group/%s/instance/remove' % (compat.convert_to_bytes(user_id),
  2459. compat.convert_to_bytes(ig_id))
  2460. body = {
  2461. "id": ig_id,
  2462. "userId": user_id,
  2463. "resourceIdList": resource_id_list
  2464. }
  2465. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
  2466. @required(user_id=str, ig_id=str, service_name=str, type_name=str, region=str, view_type=str,
  2467. page_no=int, page_size=int)
  2468. def list_ig_instance(self, user_id, ig_id, service_name, type_name, region, view_type, page_no, page_size):
  2469. """
  2470. :param user_id: user id
  2471. :type user_id: string
  2472. :param ig_id: instance group id
  2473. :type ig_id: string
  2474. :param service_name: service name
  2475. :type service_name: string
  2476. :param type_name: type name
  2477. :type type_name: string
  2478. :param region: region
  2479. :type region: string
  2480. :param view_type: view type, enum: LIST_VIEW, DETAIL_VIEW
  2481. :type view_type: string
  2482. :param page_no: page number
  2483. :type page_no: int
  2484. :param page_size: page size
  2485. :type page_size: int
  2486. """
  2487. path = b'/userId/%s/instance-group/instance/list' % compat.convert_to_bytes(user_id)
  2488. params = {
  2489. b"id": ig_id,
  2490. b"userId": user_id,
  2491. b"serviceName": service_name,
  2492. b"typeName": type_name,
  2493. b"region": region,
  2494. b"viewType": view_type,
  2495. b"pageNo": page_no,
  2496. b"pageSize": page_size
  2497. }
  2498. return self._send_csm_request(http_methods.GET, path, params=params)
  2499. @required(user_id=str, service_name=str, type_name=str, region=str, view_type=str, keyword_type=str, keyword=str,
  2500. page_no=int, page_size=int)
  2501. def list_all_instance(self, user_id, service_name, type_name, region, view_type, keyword_type, keyword,
  2502. page_no, page_size):
  2503. """
  2504. :param user_id: user id
  2505. :type user_id: string
  2506. :param service_name: service name
  2507. :type service_name: string
  2508. :param type_name: type name
  2509. :type type_name: string
  2510. :param region: region
  2511. :type region: string
  2512. :param view_type: view type, enum: LIST_VIEW, DETAIL_VIEW
  2513. :type view_type: string
  2514. :param keyword_type: keyword type, enum: name, id
  2515. :type keyword_type: string
  2516. :param keyword: keyword
  2517. :type keyword: string
  2518. :param page_no: page number
  2519. :type page_no: int
  2520. :param page_size: page size
  2521. :type page_size: int
  2522. """
  2523. path = b'/userId/%s/instance/list' % compat.convert_to_bytes(user_id)
  2524. params = {
  2525. b"userId": user_id,
  2526. b"serviceName": service_name,
  2527. b"typeName": type_name,
  2528. b"region": region,
  2529. b"viewType": view_type,
  2530. b"keywordType": keyword_type,
  2531. b"keyword": keyword,
  2532. b"pageNo": page_no,
  2533. b"pageSize": page_size
  2534. }
  2535. return self._send_csm_request(http_methods.GET, path, params=params)
  2536. @required(user_id=str, ig_id=str, ig_uuid=str, service_name=str, type_name=str, region=str, view_type=str,
  2537. keyword_type=str, keyword=str, page_no=int, page_size=int)
  2538. def list_filter_instance(self, user_id, ig_id, ig_uuid, service_name, type_name, region, view_type,
  2539. keyword_type, keyword, page_no, page_size):
  2540. """
  2541. :param user_id: user id
  2542. :type user_id: string
  2543. :param ig_id: instance group id
  2544. :type ig_id: string
  2545. :param ig_uuid: instance group uuid
  2546. :type ig_uuid: string
  2547. :param service_name: service name
  2548. :type service_name: string
  2549. :param type_name: type name
  2550. :type type_name: string
  2551. :param region: region
  2552. :type region: string
  2553. :param view_type: view type, enum: LIST_VIEW, DETAIL_VIEW
  2554. :type view_type: string
  2555. :param keyword_type: keyword type, enum: name, id
  2556. :type keyword_type: string
  2557. :param keyword: keyword
  2558. :type keyword: string
  2559. :param page_no: page number
  2560. :type page_no: int
  2561. :param page_size: page size
  2562. :type page_size: int
  2563. """
  2564. path = b'/userId/%s/instance/filteredList' % compat.convert_to_bytes(user_id)
  2565. params = {
  2566. b"userId": user_id,
  2567. b"id": ig_id,
  2568. b"uuid": ig_uuid,
  2569. b"serviceName": service_name,
  2570. b"typeName": type_name,
  2571. b"region": region,
  2572. b"viewType": view_type,
  2573. b"keywordType": keyword_type,
  2574. b"keyword": keyword,
  2575. b"pageNo": page_no,
  2576. b"pageSize": page_size
  2577. }
  2578. return self._send_csm_request(http_methods.GET, path, params=params)
  2579. def push_metric_data(self, user_id=None, scope=None, metric_data=None, config=None):
  2580. """
  2581. :param user_id: user_id
  2582. :type user_id: string
  2583. :param scope: scope
  2584. :type scope: string
  2585. :param metric_data: metric_data
  2586. :type bcm_model.MetricDatum array
  2587. :return:
  2588. """
  2589. user_id = compat.convert_to_bytes(user_id)
  2590. scope = compat.convert_to_bytes(scope)
  2591. path = b'/metricdata/%s/%s' % (user_id, scope)
  2592. body = {
  2593. "metricData": metric_data
  2594. }
  2595. return self._send_request(http_methods.POST, path, body=json.dumps(body), config=config)
  2596. def get_custom_metric_data(self, user_id=None, namespaces=None, metric_name=None,
  2597. dimensions=None, statistics=None, start_time=None,
  2598. end_time=None, cycle=None, config=None):
  2599. """
  2600. Return metric data of product instances owned by the authenticated user.
  2601. This site may help you: https://cloud.baidu.com/doc/BCM/s/9jwvym3kb
  2602. :param user_id:
  2603. Master account ID
  2604. :type user_id: string
  2605. :param namespaces:
  2606. Cloud product namespace, eg: BCE_BCC.
  2607. :type namespaces: string
  2608. :param metric_name:
  2609. The metric name of baidu cloud monitor, eg: CpuIdlePercent.
  2610. :type metric_name: string
  2611. :param dimensions:
  2612. Consists of dimensionName: dimensionValue.
  2613. Use semicolons when items have multiple dimensions,
  2614. such as dimensionName: dimensionValue; dimensionName: dimensionValue.
  2615. Only one dimension value can be specified for the same dimension.
  2616. eg: InstanceId:fakeid-2222
  2617. :type dimensions: string
  2618. :param statistics:
  2619. According to the format of statistics1,statistics2,statistics3,
  2620. the optional values are `average`, `maximum`, `minimum`, `sum`, `sampleCount`
  2621. :type statistics: string
  2622. :param start_time:
  2623. Query start time.
  2624. Please refer to the date and time, UTC date indication
  2625. :type start_time: string
  2626. :param end_time:
  2627. Query end time.
  2628. Please refer to the date and time, UTC date indication
  2629. :type end_time: string
  2630. :param cycle:
  2631. Statistical period.
  2632. Multiples of 60 in seconds (s).
  2633. :type cycle: int
  2634. :param config:
  2635. :type config: baidubce.BceClientConfiguration
  2636. :return:
  2637. :rtype baidubce.bce_response.BceResponse
  2638. """
  2639. user_id = compat.convert_to_bytes(user_id)
  2640. namespaces = compat.convert_to_bytes(namespaces)
  2641. metric_name = compat.convert_to_bytes(metric_name)
  2642. path = b'/userId/%s/custom/namespaces/%s/metrics/%s/data' % (user_id, namespaces, metric_name)
  2643. body = {
  2644. "statistics": statistics,
  2645. "dimensions": dimensions,
  2646. "startTime": start_time,
  2647. "endTime": end_time,
  2648. "cycle": cycle
  2649. }
  2650. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body),
  2651. body_parser=bcm_handler.parse_json_list, config=config)
  2652. def push_custom_metric_data(self, user_id=None, namespace=None, metric_name=None,
  2653. dimensions=None, value=None,
  2654. timestamp=None, config=None):
  2655. """
  2656. :param user_id:
  2657. :type user_id: string
  2658. :param namespace:
  2659. :type namespace: string
  2660. :param metric_name:
  2661. :type metric_name: string
  2662. :param dimensions:
  2663. :type dimensions: bcm_model.Dimension array
  2664. :param value:
  2665. :type value: double
  2666. :param timestamp:
  2667. :type timestamp: string
  2668. :param config:
  2669. :return:
  2670. """
  2671. user_id = compat.convert_to_bytes(user_id)
  2672. namespace = compat.convert_to_bytes(namespace)
  2673. path = b'/userId/%s/custom/data' % (user_id)
  2674. body = {
  2675. "namespace": namespace,
  2676. "metricName": metric_name,
  2677. "dimensions": dimensions,
  2678. "value": value,
  2679. "timestamp": timestamp
  2680. }
  2681. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  2682. def create_site_http_task_config(self, user_id=None, task_name=None, address=None,
  2683. method=None, post_content=None,
  2684. advance_config=None, cycle=None, idc=None, timeout=None, config=None):
  2685. """
  2686. :param user_id:
  2687. :type user_id: string
  2688. :param task_name:
  2689. :type task_name: string
  2690. :param address:
  2691. :type address: string
  2692. :param method:
  2693. :type method: string
  2694. :param post_content:
  2695. :type post_content: string
  2696. :param advance_config:
  2697. :type advance_config: bool
  2698. :param cycle:
  2699. :type cycle: int
  2700. :param idc:
  2701. :type idc: string
  2702. :param timeout:
  2703. :type timeout: int
  2704. :param config:
  2705. :type config
  2706. :return:
  2707. """
  2708. user_id = compat.convert_to_bytes(user_id)
  2709. path = b'/userId/%s/site/http/create' % (user_id)
  2710. body = {
  2711. "userId": user_id,
  2712. "taskName": task_name,
  2713. "address": address,
  2714. "method": method,
  2715. "postContent": post_content,
  2716. "advanceConfig": advance_config,
  2717. "cycle": cycle,
  2718. "idc": idc,
  2719. "timeout": timeout,
  2720. }
  2721. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  2722. def update_site_http_task_config(self, user_id=None, task_id=None, task_name=None, address=None,
  2723. method=None, post_content=None,
  2724. advance_config=None, cycle=None, idc=None, timeout=None, config=None):
  2725. """
  2726. :param user_id:
  2727. :type user_id: string
  2728. :param task_id:
  2729. :type task_id: string
  2730. :param task_name:
  2731. :type task_name: string
  2732. :param address:
  2733. :type address: string
  2734. :param method:
  2735. :type method: string
  2736. :param post_content:
  2737. :type post_content: string
  2738. :param advance_config:
  2739. :type advance_config: bool
  2740. :param cycle:
  2741. :type cycle: int
  2742. :param idc:
  2743. :type idc: string
  2744. :param timeout:
  2745. :type timeout: int
  2746. :param config:
  2747. :type config
  2748. :return:
  2749. """
  2750. user_id = compat.convert_to_bytes(user_id)
  2751. path = b'/userId/%s/site/http/update' % (user_id)
  2752. body = {
  2753. "userId": user_id,
  2754. "taskId": task_id,
  2755. "taskName": task_name,
  2756. "address": address,
  2757. "method": method,
  2758. "postContent": post_content,
  2759. "advanceConfig": advance_config,
  2760. "cycle": cycle,
  2761. "idc": idc,
  2762. "timeout": timeout,
  2763. }
  2764. return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
  2765. def get_site_http_task_config(self, user_id=None, task_id=None, config=None):
  2766. """
  2767. :param user_id:
  2768. :type user_id: string
  2769. :param task_id:
  2770. :type task_id: string
  2771. :param config:
  2772. :type config
  2773. :return:
  2774. """
  2775. user_id = compat.convert_to_bytes(user_id)
  2776. path = b'/userId/%s/site/http/detail' % (user_id)
  2777. params = {}
  2778. if task_id is not None:
  2779. params["taskId"] = task_id
  2780. return self._send_csm_request(http_methods.GET, path, params=params, config=config)
  2781. def create_site_https_task_config(self, user_id=None, task_name=None, address=None,
  2782. method=None, post_content=None,
  2783. advance_config=None, cycle=None, idc=None, timeout=None, config=None):
  2784. """
  2785. :param user_id:
  2786. :type user_id: string
  2787. :param task_name:
  2788. :type task_name: string
  2789. :param address:
  2790. :type address: string
  2791. :param method:
  2792. :type method: string
  2793. :param post_content:
  2794. :type post_content: string
  2795. :param advance_config:
  2796. :type advance_config: bool
  2797. :param cycle:
  2798. :type cycle: int
  2799. :param idc:
  2800. :type idc: string
  2801. :param timeout:
  2802. :type timeout: int
  2803. :param config:
  2804. :type config
  2805. :return:
  2806. """
  2807. user_id = compat.convert_to_bytes(user_id)
  2808. path = b'/userId/%s/site/https/create' % (user_id)
  2809. body = {
  2810. "userId": user_id,
  2811. "taskName": task_name,
  2812. "address": address,
  2813. "method": method,
  2814. "postContent": post_content,
  2815. "advanceConfig": advance_config,
  2816. "cycle": cycle,
  2817. "idc": idc,
  2818. "timeout": timeout,
  2819. }
  2820. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  2821. def update_site_https_task_config(self, user_id=None, task_id=None, task_name=None, address=None,
  2822. method=None, post_content=None,
  2823. advance_config=None, cycle=None, idc=None, timeout=None, config=None):
  2824. """
  2825. :param user_id:
  2826. :type user_id: string
  2827. :param task_id:
  2828. :type task_id: string
  2829. :param task_name:
  2830. :type task_name: string
  2831. :param address:
  2832. :type address: string
  2833. :param method:
  2834. :type method: string
  2835. :param post_content:
  2836. :type post_content: string
  2837. :param advance_config:
  2838. :type advance_config: bool
  2839. :param cycle:
  2840. :type cycle: int
  2841. :param idc:
  2842. :type idc: string
  2843. :param timeout:
  2844. :type timeout: int
  2845. :param config:
  2846. :type config
  2847. :return:
  2848. """
  2849. user_id = compat.convert_to_bytes(user_id)
  2850. path = b'/userId/%s/site/https/update' % (user_id)
  2851. body = {
  2852. "userId": user_id,
  2853. "taskId": task_id,
  2854. "taskName": task_name,
  2855. "address": address,
  2856. "method": method,
  2857. "postContent": post_content,
  2858. "advanceConfig": advance_config,
  2859. "cycle": cycle,
  2860. "idc": idc,
  2861. "timeout": timeout,
  2862. }
  2863. return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
  2864. def get_site_https_task_config(self, user_id=None, task_id=None, config=None):
  2865. """
  2866. :param user_id:
  2867. :type user_id: string
  2868. :param task_id:
  2869. :type task_id: string
  2870. :param config:
  2871. :type config
  2872. :return:
  2873. """
  2874. user_id = compat.convert_to_bytes(user_id)
  2875. path = b'/userId/%s/site/https/detail' % (user_id)
  2876. params = {}
  2877. if task_id is not None:
  2878. params["taskId"] = task_id
  2879. return self._send_csm_request(http_methods.GET, path, params=params, config=config)
  2880. def create_site_ping_task_config(self, user_id=None, task_name=None, address=None,
  2881. packet_count=None, packet_loss_rate=None, cycle=None, idc=None,
  2882. timeout=None, config=None):
  2883. """
  2884. :param user_id:
  2885. :type user_id: string
  2886. :param task_name:
  2887. :type task_name: string
  2888. :param address:
  2889. :type address: string
  2890. :param packet_count:
  2891. :type packet_count: int
  2892. :param packet_loss_rate:
  2893. :type packet_loss_rate: int
  2894. :param cycle:
  2895. :type cycle: int
  2896. :param idc:
  2897. :type idc: string
  2898. :param timeout:
  2899. :type timeout: int
  2900. :param config:
  2901. :type config
  2902. :return:
  2903. """
  2904. user_id = compat.convert_to_bytes(user_id)
  2905. path = b'/userId/%s/site/ping/create' % (user_id)
  2906. body = {
  2907. "userId": user_id,
  2908. "taskName": task_name,
  2909. "address": address,
  2910. "packetCount": packet_count,
  2911. "packetLossRate": packet_loss_rate,
  2912. "cycle": cycle,
  2913. "idc": idc,
  2914. "timeout": timeout,
  2915. }
  2916. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  2917. def update_site_ping_task_config(self, user_id=None, task_id=None, task_name=None, address=None,
  2918. packet_count=None, packet_loss_rate=None, cycle=None, idc=None,
  2919. timeout=None, config=None):
  2920. """
  2921. :param user_id:
  2922. :type user_id: string
  2923. :param task_id:
  2924. :type task_id: string
  2925. :param task_name:
  2926. :type task_name: string
  2927. :param address:
  2928. :type address: string
  2929. :param packet_count:
  2930. :type packet_count: int
  2931. :param packet_loss_rate:
  2932. :type packet_loss_rate: int
  2933. :param cycle:
  2934. :type cycle: int
  2935. :param idc:
  2936. :type idc: string
  2937. :param timeout:
  2938. :type timeout: int
  2939. :param config:
  2940. :type config
  2941. :return:
  2942. """
  2943. user_id = compat.convert_to_bytes(user_id)
  2944. path = b'/userId/%s/site/ping/update' % (user_id)
  2945. body = {
  2946. "userId": user_id,
  2947. "taskId": task_id,
  2948. "taskName": task_name,
  2949. "address": address,
  2950. "packetCount": packet_count,
  2951. "packetLossRate": packet_loss_rate,
  2952. "cycle": cycle,
  2953. "idc": idc,
  2954. "timeout": timeout,
  2955. }
  2956. return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
  2957. def get_site_ping_task_config(self, user_id=None, task_id=None, config=None):
  2958. """
  2959. :param user_id:
  2960. :type user_id: string
  2961. :param task_id:
  2962. :type task_id: string
  2963. :param config:
  2964. :type config
  2965. :return:
  2966. """
  2967. user_id = compat.convert_to_bytes(user_id)
  2968. path = b'/userId/%s/site/ping/detail' % (user_id)
  2969. params = {}
  2970. if task_id is not None:
  2971. params["taskId"] = task_id
  2972. return self._send_csm_request(http_methods.GET, path, params=params, config=config)
  2973. def create_site_tcp_task_config(self, user_id=None, task_name=None, address=None,
  2974. port=None, advance_config=None, cycle=None, idc=None, timeout=None,
  2975. input_type=None, output_type=None, input=None, expected_output=None, config=None):
  2976. """
  2977. :param user_id:
  2978. :type user_id: string
  2979. :param task_name:
  2980. :type task_name: string
  2981. :param address:
  2982. :type address: string
  2983. :param method:
  2984. :type method: string
  2985. :param post_content:
  2986. :type post_content: string
  2987. :param advance_config:
  2988. :type advance_config: bool
  2989. :param cycle:
  2990. :type cycle: int
  2991. :param idc:
  2992. :type idc: string
  2993. :param timeout:
  2994. :type timeout: int
  2995. :param config:
  2996. :type config
  2997. :return:
  2998. """
  2999. user_id = compat.convert_to_bytes(user_id)
  3000. path = b'/userId/%s/site/tcp/create' % (user_id)
  3001. body = {
  3002. "userId": user_id,
  3003. "taskName": task_name,
  3004. "address": address,
  3005. "port": port,
  3006. "advanceConfig": advance_config,
  3007. "inputType": input_type,
  3008. "outputType": output_type,
  3009. "input": input,
  3010. "expectedOutput": expected_output,
  3011. "cycle": cycle,
  3012. "idc": idc,
  3013. "timeout": timeout,
  3014. }
  3015. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  3016. def update_site_tcp_task_config(self, user_id=None, task_id=None, task_name=None, address=None,
  3017. port=None, advance_config=None, cycle=None, idc=None, timeout=None,
  3018. input_type=None, output_type=None, input=None, expected_output=None, config=None):
  3019. """
  3020. :param user_id:
  3021. :type user_id: string
  3022. :param task_id:
  3023. :type task_id: string
  3024. :param task_name:
  3025. :type task_name: string
  3026. :param address:
  3027. :type address: string
  3028. :param port:
  3029. :type port: int
  3030. :param post_content:
  3031. :type post_content: string
  3032. :param advance_config:
  3033. :type advance_config: bool
  3034. :param cycle:
  3035. :type cycle: int
  3036. :param idc:
  3037. :type idc: string
  3038. :param timeout:
  3039. :type timeout: int
  3040. :param input_type:
  3041. :type input_type: int
  3042. :param output_type:
  3043. :type output_type: int
  3044. :param input:
  3045. :type input: string
  3046. :param expected_output:
  3047. :type expected_output: string
  3048. :param config:
  3049. :type config
  3050. :return:
  3051. """
  3052. user_id = compat.convert_to_bytes(user_id)
  3053. path = b'/userId/%s/site/tcp/update' % (user_id)
  3054. body = {
  3055. "userId": user_id,
  3056. "taskId": task_id,
  3057. "taskName": task_name,
  3058. "address": address,
  3059. "port": port,
  3060. "advanceConfig": advance_config,
  3061. "inputType": input_type,
  3062. "outputType": output_type,
  3063. "input": input,
  3064. "expectedOutput": expected_output,
  3065. "cycle": cycle,
  3066. "idc": idc,
  3067. "timeout": timeout,
  3068. }
  3069. return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
  3070. def get_site_tcp_task_config(self, user_id=None, task_id=None, config=None):
  3071. """
  3072. :param user_id:
  3073. :type user_id: string
  3074. :param task_id:
  3075. :type task_id: string
  3076. :param config:
  3077. :type config
  3078. :return:
  3079. """
  3080. user_id = compat.convert_to_bytes(user_id)
  3081. path = b'/userId/%s/site/tcp/detail' % (user_id)
  3082. params = {}
  3083. if task_id is not None:
  3084. params["taskId"] = task_id
  3085. return self._send_csm_request(http_methods.GET, path, params=params, config=config)
  3086. def create_site_udp_task_config(self, user_id=None, task_name=None, address=None,
  3087. port=None, advance_config=None, cycle=None, idc=None, timeout=None,
  3088. input_type=None, output_type=None, input=None, expected_output=None, config=None):
  3089. """
  3090. :param user_id:
  3091. :type user_id: string
  3092. :param task_name:
  3093. :type task_name: string
  3094. :param address:
  3095. :type address: string
  3096. :param method:
  3097. :type method: string
  3098. :param post_content:
  3099. :type post_content: string
  3100. :param advance_config:
  3101. :type advance_config: bool
  3102. :param cycle:
  3103. :type cycle: int
  3104. :param idc:
  3105. :type idc: string
  3106. :param timeout:
  3107. :type timeout: int
  3108. :param config:
  3109. :type config
  3110. :return:
  3111. """
  3112. user_id = compat.convert_to_bytes(user_id)
  3113. path = b'/userId/%s/site/udp/create' % (user_id)
  3114. body = {
  3115. "userId": user_id,
  3116. "taskName": task_name,
  3117. "address": address,
  3118. "port": port,
  3119. "advanceConfig": advance_config,
  3120. "inputType": input_type,
  3121. "outputType": output_type,
  3122. "input": input,
  3123. "expectedOutput": expected_output,
  3124. "cycle": cycle,
  3125. "idc": idc,
  3126. "timeout": timeout,
  3127. }
  3128. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  3129. def update_site_udp_task_config(self, user_id=None, task_id=None, task_name=None, address=None,
  3130. port=None, advance_config=None, cycle=None, idc=None, timeout=None,
  3131. input_type=None, output_type=None, input=None, expected_output=None, config=None):
  3132. """
  3133. :param user_id:
  3134. :type user_id: string
  3135. :param task_id:
  3136. :type task_id: string
  3137. :param task_name:
  3138. :type task_name: string
  3139. :param address:
  3140. :type address: string
  3141. :param port:
  3142. :type port: int
  3143. :param post_content:
  3144. :type post_content: string
  3145. :param advance_config:
  3146. :type advance_config: bool
  3147. :param cycle:
  3148. :type cycle: int
  3149. :param idc:
  3150. :type idc: string
  3151. :param timeout:
  3152. :type timeout: int
  3153. :param input_type:
  3154. :type input_type: int
  3155. :param output_type:
  3156. :type output_type: int
  3157. :param input:
  3158. :type input: string
  3159. :param expected_output:
  3160. :type expected_output: string
  3161. :param config:
  3162. :type config
  3163. :return:
  3164. """
  3165. user_id = compat.convert_to_bytes(user_id)
  3166. path = b'/userId/%s/site/udp/update' % (user_id)
  3167. body = {
  3168. "userId": user_id,
  3169. "taskId": task_id,
  3170. "taskName": task_name,
  3171. "address": address,
  3172. "port": port,
  3173. "advanceConfig": advance_config,
  3174. "inputType": input_type,
  3175. "outputType": output_type,
  3176. "input": input,
  3177. "expectedOutput": expected_output,
  3178. "cycle": cycle,
  3179. "idc": idc,
  3180. "timeout": timeout,
  3181. }
  3182. return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
  3183. def get_site_udp_task_config(self, user_id=None, task_id=None, config=None):
  3184. """
  3185. :param user_id:
  3186. :type user_id: string
  3187. :param task_id:
  3188. :type task_id: string
  3189. :param config:
  3190. :type config
  3191. :return:
  3192. """
  3193. user_id = compat.convert_to_bytes(user_id)
  3194. path = b'/userId/%s/site/udp/detail' % (user_id)
  3195. params = {}
  3196. if task_id is not None:
  3197. params["taskId"] = task_id
  3198. return self._send_csm_request(http_methods.GET, path, params=params, config=config)
  3199. def create_site_ftp_task_config(self, user_id=None, task_name=None, address=None,
  3200. port=None, anonymous_login=None, cycle=None, idc=None, timeout=None,
  3201. user_name=None, password=None, config=None):
  3202. """
  3203. :param user_id:
  3204. :type user_id: string
  3205. :param task_name:
  3206. :type task_name: string
  3207. :param address:
  3208. :type address: string
  3209. :param port:
  3210. :type port: int
  3211. :param post_content:
  3212. :type post_content: string
  3213. :param anonymous_login:
  3214. :type anonymous_login: bool
  3215. :param cycle:
  3216. :type cycle: int
  3217. :param idc:
  3218. :type idc: string
  3219. :param timeout:
  3220. :type timeout: int
  3221. :param user_name:
  3222. :type user_name: string
  3223. :param password:
  3224. :type password: string
  3225. :param config:
  3226. :type config
  3227. :return:
  3228. """
  3229. user_id = compat.convert_to_bytes(user_id)
  3230. path = b'/userId/%s/site/ftp/create' % (user_id)
  3231. body = {
  3232. "userId": user_id,
  3233. "taskName": task_name,
  3234. "address": address,
  3235. "port": port,
  3236. "anonymousLogin": anonymous_login,
  3237. "userName": user_name,
  3238. "password": password,
  3239. "cycle": cycle,
  3240. "idc": idc,
  3241. "timeout": timeout,
  3242. }
  3243. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  3244. def update_site_ftp_task_config(self, user_id=None, task_id=None, task_name=None, address=None,
  3245. port=None, anonymous_login=None, cycle=None, idc=None, timeout=None,
  3246. user_name=None, password=None, config=None):
  3247. """
  3248. :param user_id:
  3249. :type user_id: string
  3250. :param task_id:
  3251. :type task_id: string
  3252. :param task_name:
  3253. :type task_name: string
  3254. :param address:
  3255. :type address: string
  3256. :param port:
  3257. :type port: int
  3258. :param post_content:
  3259. :type post_content: string
  3260. :param anonymous_login:
  3261. :type anonymous_login: bool
  3262. :param cycle:
  3263. :type cycle: int
  3264. :param idc:
  3265. :type idc: string
  3266. :param timeout:
  3267. :type timeout: int
  3268. :param user_name:
  3269. :type user_name: string
  3270. :param password:
  3271. :type password: string
  3272. :param config:
  3273. :type config
  3274. :return:
  3275. """
  3276. user_id = compat.convert_to_bytes(user_id)
  3277. path = b'/userId/%s/site/ftp/update' % (user_id)
  3278. body = {
  3279. "userId": user_id,
  3280. "taskId": task_id,
  3281. "taskName": task_name,
  3282. "address": address,
  3283. "port": port,
  3284. "anonymousLogin": anonymous_login,
  3285. "userName": user_name,
  3286. "password": password,
  3287. "cycle": cycle,
  3288. "idc": idc,
  3289. "timeout": timeout,
  3290. }
  3291. return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
  3292. def get_site_ftp_task_config(self, user_id=None, task_id=None, config=None):
  3293. """
  3294. :param user_id:
  3295. :type user_id: string
  3296. :param task_id:
  3297. :type task_id: string
  3298. :param config:
  3299. :type config
  3300. :return:
  3301. """
  3302. user_id = compat.convert_to_bytes(user_id)
  3303. path = b'/userId/%s/site/ftp/detail' % (user_id)
  3304. params = {}
  3305. if task_id is not None:
  3306. params["taskId"] = task_id
  3307. return self._send_csm_request(http_methods.GET, path, params=params, config=config)
  3308. def create_site_dns_task_config(self, user_id=None, task_name=None, address=None,
  3309. cycle=None, idc=None, timeout=None,
  3310. server=None, resolve_type=None, kidnap_white=None, config=None):
  3311. """
  3312. :param user_id:
  3313. :type user_id: string
  3314. :param task_name:
  3315. :type task_name: string
  3316. :param address:
  3317. :type address: string
  3318. :param post_content:
  3319. :type post_content: string
  3320. :param cycle:
  3321. :type cycle: int
  3322. :param idc:
  3323. :type idc: string
  3324. :param timeout:
  3325. :type timeout: int
  3326. :param server:
  3327. :type server: string
  3328. :param resolve_type:
  3329. :type resolve_type: ENUM {'RECURSION', 'ITERATION'}
  3330. :param kidnap_white:
  3331. :type kidnap_white: string
  3332. :param config:
  3333. :type config
  3334. :return:
  3335. """
  3336. user_id = compat.convert_to_bytes(user_id)
  3337. path = b'/userId/%s/site/dns/create' % (user_id)
  3338. body = {
  3339. "userId": user_id,
  3340. "taskName": task_name,
  3341. "address": address,
  3342. "server": server,
  3343. "resolveType": resolve_type,
  3344. "kidnapWhite": kidnap_white,
  3345. "cycle": cycle,
  3346. "idc": idc,
  3347. "timeout": timeout,
  3348. }
  3349. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  3350. def update_site_dns_task_config(self, user_id=None, task_id=None, task_name=None, address=None,
  3351. cycle=None, idc=None, timeout=None,
  3352. server=None, resolve_type=None, kidnap_white=None, config=None):
  3353. """
  3354. :param user_id:
  3355. :type user_id: string
  3356. :param task_id:
  3357. :type task_id: string
  3358. :param task_name:
  3359. :type task_name: string
  3360. :param address:
  3361. :type address: string
  3362. :param post_content:
  3363. :type post_content: string
  3364. :param cycle:
  3365. :type cycle: int
  3366. :param idc:
  3367. :type idc: string
  3368. :param timeout:
  3369. :type timeout: int
  3370. :param server:
  3371. :type server: string
  3372. :param resolve_type:
  3373. :type resolve_type: ENUM {'RECURSION', 'ITERATION'}
  3374. :param kidnap_white:
  3375. :type kidnap_white: string
  3376. :param config:
  3377. :type config
  3378. :return:
  3379. """
  3380. user_id = compat.convert_to_bytes(user_id)
  3381. path = b'/userId/%s/site/dns/update' % (user_id)
  3382. body = {
  3383. "userId": user_id,
  3384. "taskId": task_id,
  3385. "taskName": task_name,
  3386. "address": address,
  3387. "server": server,
  3388. "resolveType": resolve_type,
  3389. "kidnapWhite": kidnap_white,
  3390. "cycle": cycle,
  3391. "idc": idc,
  3392. "timeout": timeout,
  3393. }
  3394. return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
  3395. def get_site_dns_task_config(self, user_id=None, task_id=None, config=None):
  3396. """
  3397. :param user_id:
  3398. :type user_id: string
  3399. :param task_id:
  3400. :type task_id: string
  3401. :param config:
  3402. :type config
  3403. :return:
  3404. """
  3405. user_id = compat.convert_to_bytes(user_id)
  3406. path = b'/userId/%s/site/dns/detail' % (user_id)
  3407. params = {}
  3408. if task_id is not None:
  3409. params["taskId"] = task_id
  3410. return self._send_csm_request(http_methods.GET, path, params=params, config=config)
  3411. def get_site_task_config_list(self, user_id=None, query=None, type=None, page_no=None, page_size=None, config=None):
  3412. """
  3413. :param user_id:
  3414. :type user_id: string
  3415. :param query:
  3416. :type query: string
  3417. :param type:
  3418. :type type: string
  3419. :param page_no:
  3420. :type page_no: int
  3421. :param page_size:
  3422. :type page_size: int
  3423. :param config:
  3424. :type config:
  3425. :return:
  3426. """
  3427. user_id = compat.convert_to_bytes(user_id)
  3428. path = b'/userId/%s/site/list' % (user_id)
  3429. if query is None:
  3430. query = "NAME:"
  3431. params = {
  3432. b'query': query,
  3433. b'type': type,
  3434. }
  3435. if page_no is None:
  3436. params[b'pageNo'] = 1
  3437. else:
  3438. params[b'pageNo'] = page_no
  3439. if page_size is None:
  3440. params[b'pageSize'] = 10
  3441. else:
  3442. params[b'pageSize'] = page_size
  3443. return self._send_csm_request(http_methods.GET, path, params=params, config=config)
  3444. def delete_site_task_config(self, user_id=None, task_id=None, config=None):
  3445. """
  3446. :param user_id:
  3447. :type user_id: string
  3448. :param task_Id:
  3449. :type task_Id: string
  3450. :param config:
  3451. :type config:
  3452. :return:
  3453. """
  3454. user_id = compat.convert_to_bytes(user_id)
  3455. path = b'/userId/%s/site/delete' % (user_id)
  3456. params = {
  3457. b'taskId': task_id,
  3458. }
  3459. return self._send_csm_request(http_methods.DELETE, path, params=params, config=config)
  3460. def get_site_task_config_info(self, user_id=None, task_id=None, config=None):
  3461. """
  3462. :param user_id:
  3463. :type user_id: string
  3464. :param task_Id:
  3465. :type task_Id: string
  3466. :param config:
  3467. :type config:
  3468. :return:
  3469. """
  3470. user_id = compat.convert_to_bytes(user_id)
  3471. task_id = compat.convert_to_bytes(task_id)
  3472. path = b'/userId/%s/site/%s' % (user_id, task_id)
  3473. return self._send_csm_request(http_methods.GET, path, config=config)
  3474. def create_site_alarm_config(self, user_id=None, task_id=None, comment=None, alias_name=None,
  3475. level=None, action_enabled=None, resume_actions=None, insufficient_actions=None,
  3476. incident_action=None, insufficient_cycle=None, rules=None, region=None,
  3477. callback_url=None, method=None, site_monitor=None, tag=None, config=None):
  3478. """
  3479. :param user_id:
  3480. :type user_id: string
  3481. :param task_id:
  3482. :type task_id: string
  3483. :param comment:
  3484. :type comment: string
  3485. :param alias_name:
  3486. :type alias_name: string
  3487. :param level:
  3488. :type level: ENUM {'NOTICE', 'WARNING', 'CRITICAL', 'MAJOR', 'CUSTOM'}
  3489. :param action_enabled:
  3490. :type action_enabled: bool
  3491. :param resume_actions:
  3492. :type :type user_id: string: string
  3493. :param insufficient_actions:
  3494. :type insufficient_actions: string
  3495. :param incident_action:
  3496. :type incident_action: string
  3497. :param insufficient_cycle:
  3498. :type insufficient_cycle: int
  3499. :param rules:
  3500. :type rules: list of SiteAlarmRule
  3501. :param region:
  3502. :type region: string
  3503. :param callback_url:
  3504. :type callback_url: string
  3505. :param method:
  3506. :type method: string
  3507. :param site_monitor:
  3508. :type site_monitor: string
  3509. :param tag:
  3510. :type tag: string
  3511. :return:
  3512. """
  3513. user_id = compat.convert_to_bytes(user_id)
  3514. path = b'/userId/%s/site/alarm/config/create' % (user_id)
  3515. body = {
  3516. "userId": user_id,
  3517. "taskId": task_id,
  3518. "comment": comment,
  3519. "aliasName": alias_name,
  3520. "level": level,
  3521. "actionEnabled": action_enabled,
  3522. "resumeActions": resume_actions,
  3523. "insufficientActions": insufficient_actions,
  3524. "incidentAction": incident_action,
  3525. "insufficientCycle": insufficient_cycle,
  3526. "rules": rules,
  3527. "region": region,
  3528. "callbackUrl": callback_url,
  3529. "method": method,
  3530. "siteMonitor": site_monitor,
  3531. "tag": tag
  3532. }
  3533. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config)
  3534. def delete_site_alarm_config(self, user_id=None, alarm_names=None, config=None):
  3535. """
  3536. :param user_id:
  3537. :type user_id: string
  3538. :param alarm_names:
  3539. :type alarm_names: list
  3540. :param config:
  3541. :type config:
  3542. :return:
  3543. """
  3544. user_id = compat.convert_to_bytes(user_id)
  3545. path = b'/userId/%s/site/alarm/config/delete' % (user_id)
  3546. body = {
  3547. "alarmNames": alarm_names
  3548. }
  3549. return self._send_csm_request(http_methods.DELETE, path, body=json.dumps(body), config=config)
  3550. def update_site_alarm_config(self, user_id=None, task_id=None, alarm_name=None, comment=None, alias_name=None,
  3551. level=None, action_enabled=None, resume_actions=None, insufficient_actions=None,
  3552. incident_action=None, insufficient_cycle=None, rules=None, region=None,
  3553. callback_url=None, method=None, site_monitor=None, tag=None, config=None):
  3554. """
  3555. :param user_id:
  3556. :type user_id: string
  3557. :param task_id:
  3558. :type task_id: string
  3559. :param alarm_name:
  3560. :type alarm_name: string
  3561. :param comment:
  3562. :type comment: string
  3563. :param alias_name:
  3564. :type alias_name: string
  3565. :param level:
  3566. :type level: ENUM {'NOTICE', 'WARNING', 'CRITICAL', 'MAJOR', 'CUSTOM'}
  3567. :param action_enabled:
  3568. :type action_enabled: bool
  3569. :param resume_actions:
  3570. :type :type user_id: string: string
  3571. :param insufficient_actions:
  3572. :type insufficient_actions: string
  3573. :param incident_action:
  3574. :type incident_action: string
  3575. :param insufficient_cycle:
  3576. :type insufficient_cycle: int
  3577. :param rules:
  3578. :type rules: list of SiteAlarmRule
  3579. :param region:
  3580. :type region: string
  3581. :param callback_url:
  3582. :type callback_url: string
  3583. :param method:
  3584. :type method: string
  3585. :param site_monitor:
  3586. :type site_monitor: string
  3587. :param tag:
  3588. :type tag: string
  3589. :return:
  3590. """
  3591. user_id = compat.convert_to_bytes(user_id)
  3592. path = b'/userId/%s/site/alarm/config/update' % (user_id)
  3593. body = {
  3594. "userId": user_id,
  3595. "taskId": task_id,
  3596. "alarmName": alarm_name,
  3597. "comment": comment,
  3598. "aliasName": alias_name,
  3599. "level": level,
  3600. "actionEnabled": action_enabled,
  3601. "resumeActions": resume_actions,
  3602. "insufficientActions": insufficient_actions,
  3603. "incidentAction": incident_action,
  3604. "insufficientCycle": insufficient_cycle,
  3605. "rules": rules,
  3606. "region": region,
  3607. "callbackUrl": callback_url,
  3608. "method": method,
  3609. "siteMonitor": site_monitor,
  3610. "tag": tag
  3611. }
  3612. return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config)
  3613. def get_site_alarm_config_detail(self, user_id=None, alarm_name=None, config=None):
  3614. """
  3615. :param user_id:
  3616. :type user_id: string
  3617. :param alarm_name:
  3618. :type alarm_name: string
  3619. :param config:
  3620. :type config:
  3621. :return:
  3622. """
  3623. user_id = compat.convert_to_bytes(user_id)
  3624. path = b'/userId/%s/site/alarm/config/detail' % (user_id)
  3625. params = {
  3626. b'alarmName': alarm_name,
  3627. }
  3628. return self._send_csm_request(http_methods.GET, path, params=params, config=config)
  3629. def get_site_alarm_config_list(self, user_id=None, task_id=None, alarm_name=None,
  3630. action_enabled=None, page_no=None, page_size=None, config=None):
  3631. """
  3632. :param user_id:
  3633. :type user_id: string
  3634. :param task_id:
  3635. :type task_id: string
  3636. :param alarm_name:
  3637. :type alarm_name: string
  3638. :param action_enabled:
  3639. :type action_enabled: bool
  3640. :param page_no:
  3641. :type page_no: int
  3642. :param page_size:
  3643. :type page_size: int
  3644. :param config:
  3645. :return:
  3646. """
  3647. user_id = compat.convert_to_bytes(user_id)
  3648. path = b'/userId/%s/site/alarm/config/list' % (user_id)
  3649. params = {}
  3650. if task_id is not None:
  3651. params[b'taskId'] = task_id
  3652. if alarm_name is not None:
  3653. params[b'alarmName'] = alarm_name
  3654. if action_enabled is not None:
  3655. params[b'actionEnabled'] = action_enabled
  3656. if page_no is None:
  3657. params[b'pageNo'] = 1
  3658. else:
  3659. params[b'pageNo'] = page_no
  3660. if page_size is None:
  3661. params[b'pageSize'] = 10
  3662. else:
  3663. params[b'pageSize'] = page_size
  3664. return self._send_csm_request(http_methods.GET, path, params=params, config=config)
  3665. def block_site_alarm_config(self, user_id=None, alarm_name=None, namespace=None, config=None):
  3666. """
  3667. :param user_id:
  3668. :type user_id: string
  3669. :param alarm_name:
  3670. :type alarm_name: string
  3671. :param config:
  3672. :type config:
  3673. :return:
  3674. """
  3675. user_id = compat.convert_to_bytes(user_id)
  3676. path = b'/userId/%s/site/alarm/config/block' % (user_id)
  3677. params = {
  3678. "alarmName": alarm_name,
  3679. "namespace": namespace
  3680. }
  3681. return self._send_csm_request(http_methods.POST, path, params=params, config=config)
  3682. def unblock_site_alarm_config(self, user_id=None, alarm_name=None, namespace=None, config=None):
  3683. """
  3684. :param user_id:
  3685. :type user_id: string
  3686. :param alarm_name:
  3687. :type alarm_name: string
  3688. :param config:
  3689. :type config:
  3690. :return:
  3691. """
  3692. user_id = compat.convert_to_bytes(user_id)
  3693. path = b'/userId/%s/site/alarm/config/unblock' % (user_id)
  3694. params = {
  3695. "alarmName": alarm_name,
  3696. "namespace": namespace
  3697. }
  3698. return self._send_csm_request(http_methods.POST, path, params=params, config=config)
  3699. def get_site_metric_data(self, user_id=None, task_id=None, metric_name=None, statistics=None,
  3700. start_time=None, end_time=None, cycle=None,
  3701. dimensions=None, config=None):
  3702. """
  3703. :param user_id:
  3704. :type user_id: string
  3705. :param task_id:
  3706. :type task_id: string
  3707. :param metric_name:
  3708. :type metric_name: string
  3709. :param statistics:
  3710. :type statistics: list
  3711. :param start_time:
  3712. :type start_time: string
  3713. :param end_time:
  3714. :type end_time: string
  3715. :param cycle:
  3716. :type cycle: int
  3717. :param dimensions:
  3718. :type dimensions: string
  3719. :param config:
  3720. :return:
  3721. """
  3722. user_id = compat.convert_to_bytes(user_id)
  3723. path = b'/userId/%s/site/metricSiteData' % (user_id)
  3724. params = {
  3725. "taskId": task_id,
  3726. }
  3727. if metric_name is not None:
  3728. params[b'metricName'] = metric_name
  3729. if dimensions is not None:
  3730. params[b'dimensions'] = dimensions
  3731. if statistics is not None and len(statistics) > 0:
  3732. params[b'statistics'] = ",".join(statistics)
  3733. if start_time is not None:
  3734. params[b'startTime'] = start_time
  3735. if end_time is not None:
  3736. params[b'endTime'] = end_time
  3737. if cycle is not None:
  3738. params[b'cycle'] = cycle
  3739. return self._send_csm_request(http_methods.GET, path, params=params,
  3740. body_parser=bcm_handler.parse_json_list, config=config)
  3741. def get_site_overall_view(self, user_id=None, task_id=None, config=None):
  3742. """
  3743. :param user_id:
  3744. :type user_id: string
  3745. :param task_id:
  3746. :type task_id: string
  3747. :param config:
  3748. :type config:
  3749. :return:
  3750. """
  3751. user_id = compat.convert_to_bytes(user_id)
  3752. path = b'/userId/%s/site/idc/overallView' % (user_id)
  3753. params = {
  3754. "taskId": task_id
  3755. }
  3756. return self._send_csm_request(http_methods.GET, path, params=params,
  3757. body_parser=bcm_handler.parse_json_list, config=config)
  3758. def get_site_provincial_view(self, user_id=None, task_id=None, isp=None, config=None):
  3759. """
  3760. :param user_id:
  3761. :type user_id: string
  3762. :param task_id:
  3763. :type task_id: string
  3764. :param isp:
  3765. :type isp: string
  3766. :param config:
  3767. :type config:
  3768. :return:
  3769. """
  3770. user_id = compat.convert_to_bytes(user_id)
  3771. path = b'/userId/%s/site/idc/provincialView' % (user_id)
  3772. params = {
  3773. "taskId": task_id,
  3774. "isp": isp
  3775. }
  3776. return self._send_csm_request(http_methods.GET, path, params=params,
  3777. body_parser=bcm_handler.parse_json_list, config=config)
  3778. def get_site_agent(self, user_id=None, config=None):
  3779. """
  3780. :param user_id:
  3781. :type user_id: string
  3782. :param config:
  3783. :type config:
  3784. :return:
  3785. """
  3786. user_id = compat.convert_to_bytes(user_id)
  3787. path = b'/userId/%s/site/agent/list' % (user_id)
  3788. return self._send_csm_request(http_methods.GET, path, body_parser=bcm_handler.parse_json_list, config=config)
  3789. def get_site_agent_for_task(self, user_id=None, task_id=None, config=None):
  3790. """
  3791. :param user_id:
  3792. :type user_id: string
  3793. :param task_id:
  3794. :type task_id: string
  3795. :param config:
  3796. :type config:
  3797. :return:
  3798. """
  3799. user_id = compat.convert_to_bytes(user_id)
  3800. path = b'/userId/%s/site/agent/idcIsp' % (user_id)
  3801. params = {
  3802. "taskId": task_id
  3803. }
  3804. return self._send_csm_request(http_methods.GET, path, params=params, config=config)
  3805. def create_alarm_config(self, user_id, alias_name, scope, level, region, monitor_object, alarm_actions, rules,
  3806. src_type="INSTANCE", ok_actions=None, insufficient_actions=None, config_type="NORMAL",
  3807. insufficient_cycle=0, max_repeat_count=0, repeat_alarm_cycle=0, callback_url="",
  3808. callback_token="", description="", config=None):
  3809. """
  3810. create alarm config
  3811. This site may help you: https://cloud.baidu.com/doc/BCM/s/Vks8iqqnx
  3812. :param user_id: master account id
  3813. :type user_id: string
  3814. :param alias_name: alarm config alias name
  3815. :type alias_name: string
  3816. :param scope: scope
  3817. :type scope: string
  3818. :param level: alarm level
  3819. :type level: string
  3820. :param region: alarm region
  3821. :type region: string
  3822. :param monitor_object: monitor object
  3823. :type monitor_object: MonitorObject
  3824. :param alarm_actions: alarm actions
  3825. :type alarm_actions: string array
  3826. :param rules: alarm rules
  3827. :type rules: AlarmRule double dimensional array
  3828. :param src_type: src type
  3829. :type src_type: string
  3830. :param ok_actions: ok actions
  3831. :type ok_actions: string array
  3832. :param insufficient_actions: insufficient actions
  3833. :type insufficient_actions: string array
  3834. :param config_type: alarm config type
  3835. :type config_type: string
  3836. :param insufficient_cycle: insufficient cycle
  3837. :type insufficient_cycle: int
  3838. :param max_repeat_count: max repeat count
  3839. :type max_repeat_count: int
  3840. :param repeat_alarm_cycle: repeat alarm cycle
  3841. :type repeat_alarm_cycle: int
  3842. :param callback_url: callback url
  3843. :type callback_url: string
  3844. :param callback_token: callback token
  3845. :type callback_token: string
  3846. :param description: description
  3847. :type description: string
  3848. :param config:
  3849. :type config: baidubce.BceClientConfiguration
  3850. """
  3851. if len(user_id) <= 0:
  3852. raise ValueError('user_id should not be none or empty string')
  3853. if len(alias_name) <= 0:
  3854. raise ValueError('alias_name should not be none or empty string')
  3855. if len(scope) <= 0:
  3856. raise ValueError('scope should not be none or empty string')
  3857. if len(region) <= 0:
  3858. raise ValueError('region should not be none or empty string')
  3859. if len(level) <= 0:
  3860. raise ValueError('level should not be none or empty string')
  3861. if monitor_object is None:
  3862. raise ValueError('monitor_object should not be none')
  3863. if len(alarm_actions) <= 0:
  3864. raise ValueError('alarm_actions should not be empty')
  3865. if len(rules) <= 0:
  3866. raise ValueError('rules should not be empty')
  3867. if insufficient_actions is None:
  3868. insufficient_actions = []
  3869. if ok_actions is None:
  3870. ok_actions = []
  3871. path = b'/services/alarm/config/create'
  3872. body = {
  3873. "alarmDescription": description,
  3874. "aliasName": alias_name,
  3875. "userId": user_id,
  3876. "scope": scope,
  3877. "region": region,
  3878. "level": level,
  3879. "monitorObject": monitor_object,
  3880. "alarmActions": alarm_actions,
  3881. "okActions": ok_actions,
  3882. "insufficientActions": insufficient_actions,
  3883. "srcType": src_type,
  3884. "type": config_type,
  3885. "insufficientCycle": insufficient_cycle,
  3886. "maxRepeatCount": max_repeat_count,
  3887. "repeatAlarmCycle": repeat_alarm_cycle,
  3888. "callbackUrl": callback_url,
  3889. "callbackToken": callback_token,
  3890. "rules": rules,
  3891. }
  3892. self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
  3893. def update_alarm_config(self, user_id, alarm_name, alias_name, scope, level, region,
  3894. monitor_object, alarm_actions, rules,
  3895. src_type="INSTANCE", ok_actions=None, insufficient_actions=None, config_type="NORMAL",
  3896. insufficient_cycle=0, max_repeat_count=0, repeat_alarm_cycle=0, callback_url="",
  3897. callback_token="", description="", config=None):
  3898. """
  3899. update alarm config
  3900. This site may help you: https://cloud.baidu.com/doc/BCM/s/Vks8iqqnx
  3901. :param user_id: master account id
  3902. :type user_id: string
  3903. :param alarm_name: alarm config name
  3904. :type alarm_name: string
  3905. :param alias_name: alarm config alias name
  3906. :type alias_name: string
  3907. :param scope: scope
  3908. :type scope: string
  3909. :param level: alarm level
  3910. :type level: string
  3911. :param region: alarm region
  3912. :type region: string
  3913. :param monitor_object: monitor object
  3914. :type monitor_object: MonitorObject
  3915. :param alarm_actions: alarm actions
  3916. :type alarm_actions: string array
  3917. :param rules: alarm rules
  3918. :type rules: AlarmRule double dimensional array
  3919. :param src_type: src type
  3920. :type src_type: string
  3921. :param ok_actions: ok actions
  3922. :type ok_actions: string array
  3923. :param insufficient_actions: insufficient actions
  3924. :type insufficient_actions: string array
  3925. :param config_type: alarm config type
  3926. :type config_type: string
  3927. :param insufficient_cycle: insufficient cycle
  3928. :type insufficient_cycle: int
  3929. :param max_repeat_count: max repeat count
  3930. :type max_repeat_count: int
  3931. :param repeat_alarm_cycle: repeat alarm cycle
  3932. :type repeat_alarm_cycle: int
  3933. :param callback_url: callback url
  3934. :type callback_url: string
  3935. :param callback_token: callback token
  3936. :type callback_token: string
  3937. :param description: description
  3938. :type description: string
  3939. :param config:
  3940. :type config: baidubce.BceClientConfiguration
  3941. """
  3942. if len(user_id) <= 0:
  3943. raise ValueError('user_id should not be none or empty string')
  3944. if len(alias_name) <= 0:
  3945. raise ValueError('alias_name should not be none or empty string')
  3946. if len(alarm_name) <= 0:
  3947. raise ValueError('alarm_name should not be none or empty string')
  3948. if len(scope) <= 0:
  3949. raise ValueError('scope should not be none or empty string')
  3950. if len(region) <= 0:
  3951. raise ValueError('region should not be none or empty string')
  3952. if len(level) <= 0:
  3953. raise ValueError('level should not be none or empty string')
  3954. if monitor_object is None:
  3955. raise ValueError('monitor_object should not be none')
  3956. if len(alarm_actions) <= 0:
  3957. raise ValueError('alarm_actions should not be empty')
  3958. if len(rules) <= 0:
  3959. raise ValueError('rules should not be empty')
  3960. if insufficient_actions is None:
  3961. insufficient_actions = []
  3962. if ok_actions is None:
  3963. ok_actions = []
  3964. path = b'/services/alarm/config/update'
  3965. body = {
  3966. "alarmDescription": description,
  3967. "alarmName": alarm_name,
  3968. "aliasName": alias_name,
  3969. "userId": user_id,
  3970. "scope": scope,
  3971. "region": region,
  3972. "level": level,
  3973. "monitorObject": monitor_object,
  3974. "alarmActions": alarm_actions,
  3975. "okActions": ok_actions,
  3976. "insufficientActions": insufficient_actions,
  3977. "srcType": src_type,
  3978. "type": config_type,
  3979. "insufficientCycle": insufficient_cycle,
  3980. "maxRepeatCount": max_repeat_count,
  3981. "repeatAlarmCycle": repeat_alarm_cycle,
  3982. "callbackUrl": callback_url,
  3983. "callbackToken": callback_token,
  3984. "rules": rules,
  3985. }
  3986. self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
  3987. def delete_alarm_config(self, user_id, alarm_name, scope, config=None):
  3988. """
  3989. delete alarm config
  3990. This site may help you: https://cloud.baidu.com/doc/BCM/s/Vks8iqqnx
  3991. :param user_id: master account id
  3992. :type user_id: string
  3993. :param alarm_name: alarm config name
  3994. :type alarm_name: string
  3995. :param scope: scope
  3996. :type scope: string
  3997. :param config:
  3998. :type config: baidubce.BceClientConfiguration
  3999. """
  4000. if len(user_id) <= 0:
  4001. raise ValueError('user_id should not be none or empty string')
  4002. if len(alarm_name) <= 0:
  4003. raise ValueError('alarm_name should not be none or empty string')
  4004. if len(scope) <= 0:
  4005. raise ValueError('scope should not be none or empty string')
  4006. path = b'/services/alarm/config/delete'
  4007. params = {
  4008. b"alarmName": alarm_name,
  4009. b"userId": user_id,
  4010. b"scope": scope,
  4011. }
  4012. self._send_csm_request(http_methods.POST, path, params=params, config=config)
  4013. def block_alarm_config(self, user_id, alarm_name, scope, config=None):
  4014. """
  4015. block alarm config
  4016. This site may help you: https://cloud.baidu.com/doc/BCM/s/Vks8iqqnx
  4017. :param user_id: master account id
  4018. :type user_id: string
  4019. :param alarm_name: alarm config name
  4020. :type alarm_name: string
  4021. :param scope: scope
  4022. :type scope: string
  4023. :param config:
  4024. :type config: baidubce.BceClientConfiguration
  4025. """
  4026. if len(user_id) <= 0:
  4027. raise ValueError('user_id should not be none or empty string')
  4028. if len(alarm_name) <= 0:
  4029. raise ValueError('alarm_name should not be none or empty string')
  4030. if len(scope) <= 0:
  4031. raise ValueError('scope should not be none or empty string')
  4032. path = b'/services/alarm/config/block'
  4033. params = {
  4034. b"alarmName": alarm_name,
  4035. b"userId": user_id,
  4036. b"scope": scope,
  4037. }
  4038. self._send_csm_request(http_methods.POST, path, params=params, config=config)
  4039. def unblock_alarm_config(self, user_id, alarm_name, scope, config=None):
  4040. """
  4041. unblock alarm config
  4042. This site may help you: https://cloud.baidu.com/doc/BCM/s/Vks8iqqnx
  4043. :param user_id: master account id
  4044. :type user_id: string
  4045. :param alarm_name: alarm config name
  4046. :type alarm_name: string
  4047. :param scope: scope
  4048. :type scope: string
  4049. :param config:
  4050. :type config: baidubce.BceClientConfiguration
  4051. """
  4052. if len(user_id) <= 0:
  4053. raise ValueError('user_id should not be none or empty string')
  4054. if len(alarm_name) <= 0:
  4055. raise ValueError('alarm_name should not be none or empty string')
  4056. if len(scope) <= 0:
  4057. raise ValueError('scope should not be none or empty string')
  4058. path = b'/services/alarm/config/unblock'
  4059. params = {
  4060. b"alarmName": alarm_name,
  4061. b"userId": user_id,
  4062. b"scope": scope,
  4063. }
  4064. self._send_csm_request(http_methods.POST, path, params=params, config=config)
  4065. def get_alarm_config_detail(self, user_id, alarm_name, scope, config=None):
  4066. """
  4067. get alarm config detail
  4068. This site may help you: https://cloud.baidu.com/doc/BCM/s/Vks8iqqnx
  4069. :param user_id: master account id
  4070. :type user_id: string
  4071. :param alarm_name: alarm config name
  4072. :type alarm_name: string
  4073. :param scope: scope
  4074. :type scope: string
  4075. :param config:
  4076. :type config: baidubce.BceClientConfiguration
  4077. :return:
  4078. :rtype baidubce.bce_response.BceResponse
  4079. """
  4080. if len(user_id) <= 0:
  4081. raise ValueError('user_id should not be none or empty string')
  4082. if len(alarm_name) <= 0:
  4083. raise ValueError('alarm_name should not be none or empty string')
  4084. if len(scope) <= 0:
  4085. raise ValueError('scope should not be none or empty string')
  4086. path = b'/services/alarm/config'
  4087. params = {
  4088. b"alarmName": alarm_name,
  4089. b"userId": user_id,
  4090. b"scope": scope,
  4091. }
  4092. return self._send_csm_request(http_methods.GET, path, params=params, config=config)
  4093. def get_single_instance_alarm_configs(self, user_id, scope, page_no, page_size,
  4094. region="bj", alarm_name_prefix="", action_enabled=None, dimensions="",
  4095. order="desc", config=None):
  4096. """
  4097. get alarm config detail
  4098. This site may help you: https://cloud.baidu.com/doc/BCM/s/Vks8iqqnx
  4099. :param user_id: master account id
  4100. :type user_id: string
  4101. :param scope: scope
  4102. :type scope: string
  4103. :param region: region
  4104. :type region: string
  4105. :param page_no: page no
  4106. :type page_no: int
  4107. :param page_size: page size
  4108. :type page_size: int
  4109. :param alarm_name_prefix: alarm name prefix
  4110. :type alarm_name_prefix: string
  4111. :param action_enabled: action enable flag
  4112. :type action_enabled: bool
  4113. :param dimensions: dimensions
  4114. :type dimensions: string
  4115. :param order: order
  4116. :type order: string
  4117. :param config:
  4118. :type config: baidubce.BceClientConfiguration
  4119. :return:
  4120. :rtype baidubce.bce_response.BceResponse
  4121. """
  4122. if len(user_id) <= 0:
  4123. raise ValueError('user_id should not be none or empty string')
  4124. if len(scope) <= 0:
  4125. raise ValueError('scope should not be none or empty string')
  4126. if page_no <= 0:
  4127. raise ValueError('page_no should be greater than 0')
  4128. if page_size <= 0:
  4129. raise ValueError('page_size should be greater than 0')
  4130. path = b'/services/alarm/config/list'
  4131. params = {
  4132. b"region": region,
  4133. b"userId": user_id,
  4134. b"scope": scope,
  4135. b"pageNo": page_no,
  4136. b"pageSize": page_size,
  4137. b"dimensions": dimensions,
  4138. b"order": order,
  4139. b"alarmNamePrefix": alarm_name_prefix,
  4140. }
  4141. if action_enabled is not None:
  4142. if action_enabled:
  4143. params["actionEnabled"] = "true"
  4144. else:
  4145. params["actionEnabled"] = "false"
  4146. return self._send_csm_request(http_methods.GET, path, params=params, config=config)
  4147. def get_alarm_metrics(self, user_id, scope, region="bj", dimensions="", metric_type="", locale="", config=None):
  4148. """
  4149. get alarm config detail
  4150. This site may help you: https://cloud.baidu.com/doc/BCM/s/Vks8iqqnx
  4151. :param user_id: master account id
  4152. :type user_id: string
  4153. :param scope: scope
  4154. :type scope: string
  4155. :param region: region
  4156. :type region: string
  4157. :param dimensions: dimensions
  4158. :type dimensions: string
  4159. :param metric_type: metric type
  4160. :type metric_type: string
  4161. :param locale: locale
  4162. :type locale: string
  4163. :param config:
  4164. :type config: baidubce.BceClientConfiguration
  4165. :return:
  4166. :rtype baidubce.bce_response.BceResponse
  4167. """
  4168. if len(user_id) <= 0:
  4169. raise ValueError('user_id should not be none or empty string')
  4170. if len(scope) <= 0:
  4171. raise ValueError('scope should not be none or empty string')
  4172. path = b'/services/alarm/config/metrics'
  4173. params = {
  4174. b"region": region,
  4175. b"userId": user_id,
  4176. b"scope": scope,
  4177. b"dimensions": dimensions,
  4178. b"type": metric_type,
  4179. b"locale": locale,
  4180. }
  4181. return self._send_csm_request(http_methods.GET, path, params=params,
  4182. body_parser=bcm_handler.parse_json_list, config=config)
  4183. def create_alarm_config_v2(self, user_id, alias_name, scope, target_type, level, region, actions, policies,
  4184. target_instances=None, insufficient_period=0,
  4185. alarm_repeat_interval=0, alarm_repeat_count=0,
  4186. callback_url="", callback_token="", target_instance_tags=None,
  4187. target_instance_groups=None, resource_type="Instance", config=None):
  4188. """
  4189. get alarm config detail
  4190. This site may help you: https://cloud.baidu.com/doc/BCM/s/blhrp7kdx
  4191. :param user_id: master account id
  4192. :type user_id: string
  4193. :param alias_name: alarm config alias name
  4194. :type alias_name: string
  4195. :param scope: scope
  4196. :type scope: string
  4197. :param target_type: alarm config target type
  4198. :type target_type: string
  4199. :param level: alarm level
  4200. :type level: string
  4201. :param region: alarm config region
  4202. :type region: string
  4203. :param actions: alarm actions
  4204. :type actions: AlarmAction array
  4205. :param policies: alarm config policies
  4206. :type policies: AlarmConfigPolicy array
  4207. :param target_instances: alarm config target instances
  4208. :type target_instances: TargetInstance array
  4209. :param insufficient_period: insufficient data pending period
  4210. :type insufficient_period: int
  4211. :param alarm_repeat_interval: alarm repeat interval
  4212. :type alarm_repeat_interval: int
  4213. :param alarm_repeat_count: alarm repeat count
  4214. :type alarm_repeat_count: int
  4215. :param callback_url: callback url
  4216. :type callback_url: string
  4217. :param callback_token: callback token
  4218. :type callback_token: string
  4219. :param target_instance_tags: target instance tags
  4220. :type target_instance_tags: KV array
  4221. :param target_instance_groups: target instance groups
  4222. :type target_instance_groups: string array
  4223. :param resource_type: resource type
  4224. :type resource_type: string
  4225. :param config:
  4226. :type config: baidubce.BceClientConfiguration
  4227. :return:
  4228. :rtype baidubce.bce_response.BceResponse
  4229. """
  4230. if len(user_id) <= 0:
  4231. raise ValueError('user_id should not be none or empty string')
  4232. if len(scope) <= 0:
  4233. raise ValueError('scope should not be none or empty string')
  4234. if len(alias_name) <= 0:
  4235. raise ValueError('alias_name should not be none or empty string')
  4236. if len(target_type) <= 0:
  4237. raise ValueError('target_type should not be none or empty string')
  4238. if len(level) <= 0:
  4239. raise ValueError('level should not be none or empty string')
  4240. if len(region) <= 0:
  4241. raise ValueError('region should not be none or empty string')
  4242. if len(actions) <= 0:
  4243. raise ValueError('actions should not be empty')
  4244. if len(policies) <= 0:
  4245. raise ValueError('policies should not be empty')
  4246. if target_type == "TARGET_TYPE_MULTI_INSTANCES" and len(target_instances) <= 0:
  4247. raise ValueError('target_instances should not be empty')
  4248. if target_type == "TARGET_TYPE_INSTANCE_GROUP" and len(target_instance_groups) <= 0:
  4249. raise ValueError('target_instance_groups should not be empty')
  4250. if target_type == "TARGET_TYPE_INSTANCE_TAGS" and len(target_instance_tags) <= 0:
  4251. raise ValueError('target_instance_tags should not be empty')
  4252. if target_instance_groups is None:
  4253. target_instance_groups = []
  4254. if target_instance_tags is None:
  4255. target_instance_tags = []
  4256. if target_instances is None:
  4257. target_instances = []
  4258. path = b'/userId/%s/services/%s/alarm/config/create' % (user_id, scope)
  4259. body = {
  4260. "userId": user_id,
  4261. "scope": scope,
  4262. "aliasName": alias_name,
  4263. "targetType": target_type,
  4264. "resourceType": resource_type,
  4265. "alarmLevel": level,
  4266. "targetInstanceGroups": target_instance_groups,
  4267. "targetInstanceTags": target_instance_tags,
  4268. "callbackUrl": callback_url,
  4269. "callbackToken": callback_token,
  4270. "insufficientDataPendingPeriod": insufficient_period,
  4271. "alarmRepeatInterval": alarm_repeat_interval,
  4272. "alarmRepeatCount": alarm_repeat_count,
  4273. "policies": policies,
  4274. "targetInstances": target_instances,
  4275. "actions": actions,
  4276. }
  4277. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body), config=config,
  4278. version=BcmClient.version_v2)
  4279. def update_alarm_config_v2(self, user_id, alarm_name, alias_name, scope, target_type, level, region,
  4280. actions, policies, target_instances=None, insufficient_period=0,
  4281. alarm_repeat_interval=0, alarm_repeat_count=0,
  4282. callback_url="", callback_token="", target_instance_tags=None,
  4283. target_instance_groups=None, resource_type="Instance", config=None):
  4284. """
  4285. get alarm config detail
  4286. This site may help you: https://cloud.baidu.com/doc/BCM/s/blhrp7kdx
  4287. :param user_id: master account id
  4288. :type user_id: string
  4289. :param alarm_name: alarm config name
  4290. :type alarm_name: string
  4291. :param alias_name: alarm config alias name
  4292. :type alias_name: string
  4293. :param scope: scope
  4294. :type scope: string
  4295. :param target_type: alarm config target type
  4296. :type target_type: string
  4297. :param level: alarm level
  4298. :type level: string
  4299. :param region: alarm config region
  4300. :type region: string
  4301. :param actions: alarm actions
  4302. :type actions: AlarmAction array
  4303. :param policies: alarm config policies
  4304. :type policies: AlarmConfigPolicy array
  4305. :param target_instances: alarm config target instances
  4306. :type target_instances: TargetInstance array
  4307. :param insufficient_period: insufficient data pending period
  4308. :type insufficient_period: int
  4309. :param alarm_repeat_interval: alarm repeat interval
  4310. :type alarm_repeat_interval: int
  4311. :param alarm_repeat_count: alarm repeat count
  4312. :type alarm_repeat_count: int
  4313. :param callback_url: callback url
  4314. :type callback_url: string
  4315. :param callback_token: callback token
  4316. :type callback_token: string
  4317. :param target_instance_tags: target instance tags
  4318. :type target_instance_tags: KV array
  4319. :param target_instance_groups: target instance groups
  4320. :type target_instance_groups: string array
  4321. :param resource_type: resource type
  4322. :type resource_type: string
  4323. :param config:
  4324. :type config: baidubce.BceClientConfiguration
  4325. :return:
  4326. :rtype baidubce.bce_response.BceResponse
  4327. """
  4328. if len(user_id) <= 0:
  4329. raise ValueError('user_id should not be none or empty string')
  4330. if len(scope) <= 0:
  4331. raise ValueError('scope should not be none or empty string')
  4332. if len(alarm_name) <= 0:
  4333. raise ValueError('alarm_name should not be none or empty string')
  4334. if len(alias_name) <= 0:
  4335. raise ValueError('alias_name should not be none or empty string')
  4336. if len(target_type) <= 0:
  4337. raise ValueError('target_type should not be none or empty string')
  4338. if len(level) <= 0:
  4339. raise ValueError('level should not be none or empty string')
  4340. if len(region) <= 0:
  4341. raise ValueError('region should not be none or empty string')
  4342. if len(actions) <= 0:
  4343. raise ValueError('actions should not be empty')
  4344. if len(policies) <= 0:
  4345. raise ValueError('policies should not be empty')
  4346. if target_type == "TARGET_TYPE_MULTI_INSTANCES" and len(target_instances) <= 0:
  4347. raise ValueError('target_instances should not be empty')
  4348. if target_type == "TARGET_TYPE_INSTANCE_GROUP" and len(target_instance_groups) <= 0:
  4349. raise ValueError('target_instance_groups should not be empty')
  4350. if target_type == "TARGET_TYPE_INSTANCE_TAGS" and len(target_instance_tags) <= 0:
  4351. raise ValueError('target_instance_tags should not be empty')
  4352. if target_instance_tags is None:
  4353. target_instance_tags = []
  4354. if target_instance_groups is None:
  4355. target_instance_groups = []
  4356. if target_instances is None:
  4357. target_instances = []
  4358. path = b'/userId/%s/services/%s/alarm/config/update' % (user_id, scope)
  4359. body = {
  4360. "userId": user_id,
  4361. "scope": scope,
  4362. "aliasName": alias_name,
  4363. "alarmName": alarm_name,
  4364. "targetType": target_type,
  4365. "resourceType": resource_type,
  4366. "alarmLevel": level,
  4367. "targetInstanceGroups": target_instance_groups,
  4368. "targetInstanceTags": target_instance_tags,
  4369. "callbackUrl": callback_url,
  4370. "callbackToken": callback_token,
  4371. "insufficientDataPendingPeriod": insufficient_period,
  4372. "alarmRepeatInterval": alarm_repeat_interval,
  4373. "alarmRepeatCount": alarm_repeat_count,
  4374. "policies": policies,
  4375. "targetInstances": target_instances,
  4376. "actions": actions,
  4377. }
  4378. return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body), config=config,
  4379. version=BcmClient.version_v2)
  4380. def block_alarm_config_v2(self, user_id, alarm_name, scope, config=None):
  4381. """
  4382. block alarm config v2
  4383. This site may help you: https://cloud.baidu.com/doc/BCM/s/blhrp7kdx
  4384. :param user_id: master account id
  4385. :type user_id: string
  4386. :param alarm_name: alarm config name
  4387. :type alarm_name: string
  4388. :param scope: scope
  4389. :type scope: string
  4390. :param config:
  4391. :type config: baidubce.BceClientConfiguration
  4392. """
  4393. if len(user_id) <= 0:
  4394. raise ValueError('user_id should not be none or empty string')
  4395. if len(alarm_name) <= 0:
  4396. raise ValueError('alarm_name should not be none or empty string')
  4397. if len(scope) <= 0:
  4398. raise ValueError('scope should not be none or empty string')
  4399. path = b'/userId/%s/services/%s/alarm/config/block' % (user_id, scope)
  4400. params = {
  4401. b"alarmName": alarm_name
  4402. }
  4403. self._send_csm_request(http_methods.POST, path, params=params, config=config,
  4404. version=BcmClient.version_v2)
  4405. def unblock_alarm_config_v2(self, user_id, alarm_name, scope, config=None):
  4406. """
  4407. unblock alarm config v2
  4408. This site may help you: https://cloud.baidu.com/doc/BCM/s/blhrp7kdx
  4409. :param user_id: master account id
  4410. :type user_id: string
  4411. :param alarm_name: alarm config name
  4412. :type alarm_name: string
  4413. :param scope: scope
  4414. :type scope: string
  4415. :param config:
  4416. :type config: baidubce.BceClientConfiguration
  4417. """
  4418. if len(user_id) <= 0:
  4419. raise ValueError('user_id should not be none or empty string')
  4420. if len(alarm_name) <= 0:
  4421. raise ValueError('alarm_name should not be none or empty string')
  4422. if len(scope) <= 0:
  4423. raise ValueError('scope should not be none or empty string')
  4424. path = b'/userId/%s/services/%s/alarm/config/unblock' % (user_id, scope)
  4425. params = {
  4426. b"alarmName": alarm_name
  4427. }
  4428. self._send_csm_request(http_methods.POST, path, params=params, config=config,
  4429. version=BcmClient.version_v2)
  4430. def get_alarm_config_detail_v2(self, user_id, alarm_name, scope, config=None):
  4431. """
  4432. get alarm config detail v2
  4433. This site may help you: https://cloud.baidu.com/doc/BCM/s/blhrp7kdx
  4434. :param user_id: master account id
  4435. :type user_id: string
  4436. :param alarm_name: alarm config name
  4437. :type alarm_name: string
  4438. :param scope: scope
  4439. :type scope: string
  4440. :param config:
  4441. :type config: baidubce.BceClientConfiguration
  4442. """
  4443. if len(user_id) <= 0:
  4444. raise ValueError('user_id should not be none or empty string')
  4445. if len(alarm_name) <= 0:
  4446. raise ValueError('alarm_name should not be none or empty string')
  4447. if len(scope) <= 0:
  4448. raise ValueError('scope should not be none or empty string')
  4449. path = b'/userId/%s/services/%s/alarm/config' % (user_id, scope)
  4450. params = {
  4451. b"alarmName": alarm_name
  4452. }
  4453. self._send_csm_request(http_methods.GET, path, params=params, config=config, version=BcmClient.version_v2)
  4454. @required(rules=list, insufficientActions=int, repeatAlarmCycle=int, maxRepeatCount=int)
  4455. def create_custom_alarm_policy(self, user_id, alarm_name, namespace, level, comment="",
  4456. action_enabled=True, policy_enabled=None, alarm_actions=None, ok_actions=None,
  4457. insufficient_actions=None, insufficient_cycle=None, rules=None, region=None,
  4458. callback_url=None, callback_token=None, tag="", repeat_alarm_cycle=0,
  4459. max_repeat_count=0):
  4460. """
  4461. :param user_id:
  4462. :type user_id: string
  4463. :param alarm_name: alarm name
  4464. :type alarm_name: string
  4465. :param namespace: custom namespace
  4466. :type namespace: string
  4467. :param level: level
  4468. :type level: string enum: NOTICE, NOTICE, CRITICAL, MAJOR
  4469. :param comment: comment
  4470. :type comment: string
  4471. :param action_enabled: is action enabled
  4472. :type action_enabled: bool
  4473. :param policy_enabled: is policy enabled
  4474. :type policy_enabled: bool
  4475. :param alarm_actions: alarm actions
  4476. :type alarm_actions: list
  4477. :param ok_actions: ok actions
  4478. :type ok_actions: list of string
  4479. :param insufficient_actions: insufficient actions
  4480. :type insufficient_actions: list of string
  4481. :param insufficient_cycle: insufficient cycle
  4482. :type insufficient_cycle: int
  4483. :param rules: rules
  4484. :type rules: list of CustomAlarmRule
  4485. :param region: region
  4486. :type region: string
  4487. :param callback_url: callback url
  4488. :type callback_url: string
  4489. :param callback_token: callback token
  4490. :type callback_token: string
  4491. :param tag: tag
  4492. :type tag: string
  4493. :param repeat_alarm_cycle: repeat alarm cycle
  4494. :type repeat_alarm_cycle: int
  4495. :param max_repeat_count: max repeat count
  4496. :type max_repeat_count: int
  4497. :return
  4498. :rtype baidubce.bce_response.BceResponse
  4499. """
  4500. path = b'/custom/alarm/configs/create'
  4501. body = {
  4502. "userId": user_id,
  4503. "alarmName": alarm_name,
  4504. "namespace": namespace,
  4505. "level": level,
  4506. "comment": comment,
  4507. "actionEnabled": action_enabled,
  4508. "policyEnabled": policy_enabled,
  4509. "alarmActions": alarm_actions,
  4510. "okActions": ok_actions,
  4511. "insufficientActions": insufficient_actions,
  4512. "insufficientCycle": insufficient_cycle,
  4513. "rules": rules,
  4514. "region": region,
  4515. "callbackUrl": callback_url,
  4516. "callbackToken": callback_token,
  4517. "repeatAlarmCycle": repeat_alarm_cycle,
  4518. "maxRepeatCount": max_repeat_count,
  4519. "tag": tag
  4520. }
  4521. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
  4522. @required(custom_alarm_list=list)
  4523. def delete_custom_alarm_policy(self, custom_alarm_list):
  4524. """
  4525. :param custom_alarm_list:
  4526. :type custom_alarm_list: list of custom alarm
  4527. :return
  4528. :rtype baidubce.bce_response.BceResponse
  4529. """
  4530. path = (b'/custom/alarm/configs/delete')
  4531. body = {
  4532. "customAlarmList": [
  4533. ]
  4534. }
  4535. for custom_alarm in custom_alarm_list:
  4536. body["customAlarmList"].append({
  4537. "scope": custom_alarm["scope"],
  4538. "userId": custom_alarm["userId"],
  4539. "alarmName": custom_alarm["alarmName"]
  4540. })
  4541. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
  4542. @required(rules=list, insufficientActions=int, repeatAlarmCycle=int, maxRepeatCount=int)
  4543. def update_custom_alarm_policy(self, user_id, alarm_name, namespace, level, comment="",
  4544. action_enabled=True, policy_enabled=None, alarm_actions=None, ok_actions=None,
  4545. insufficient_actions=None, insufficient_cycle=None, rules=None, region=None,
  4546. callback_url=None, callback_token=None, tag="", repeat_alarm_cycle=0,
  4547. max_repeat_count=0):
  4548. """
  4549. :param user_id:
  4550. :type user_id: string
  4551. :param alarm_name: alarm name
  4552. :type alarm_name: string
  4553. :param namespace: custom namespace
  4554. :type namespace: string
  4555. :param level: level
  4556. :type level: string enum: NOTICE, NOTICE, CRITICAL, MAJOR
  4557. :param comment: comment
  4558. :type comment: string
  4559. :param action_enabled: is action enabled
  4560. :type action_enabled: bool
  4561. :param policy_enabled: is policy enabled
  4562. :type policy_enabled: bool
  4563. :param alarm_actions: alarm actions
  4564. :type alarm_actions: list
  4565. :param ok_actions: ok actions
  4566. :type ok_actions: list of string
  4567. :param insufficient_actions: insufficient actions
  4568. :type insufficient_actions: list of string
  4569. :param insufficient_cycle: insufficient cycle
  4570. :type insufficient_cycle: int
  4571. :param rules: rules
  4572. :type rules: list of CustomAlarmRule
  4573. :param region: region
  4574. :type region: string
  4575. :param callback_url: callback url
  4576. :type callback_url: string
  4577. :param callback_token: callback token
  4578. :type callback_token: string
  4579. :param tag: tag
  4580. :type tag: string
  4581. :param repeat_alarm_cycle: repeat alarm cycle
  4582. :type repeat_alarm_cycle: int
  4583. :param max_repeat_count: max repeat count
  4584. :type max_repeat_count: int
  4585. :return
  4586. :rtype baidubce.bce_response.BceResponse
  4587. """
  4588. if alarm_actions is None:
  4589. alarm_actions = []
  4590. if ok_actions is None:
  4591. alarm_actions = []
  4592. if insufficient_actions is None:
  4593. insufficient_actions = []
  4594. path = b'/custom/alarm/configs/update'
  4595. body = {
  4596. "userId": user_id,
  4597. "alarmName": alarm_name,
  4598. "namespace": namespace,
  4599. "level": level,
  4600. "comment": comment,
  4601. "actionEnabled": action_enabled,
  4602. "policyEnabled": policy_enabled,
  4603. "alarmActions": alarm_actions,
  4604. "okActions": ok_actions,
  4605. "insufficientActions": insufficient_actions,
  4606. "insufficientCycle": insufficient_cycle,
  4607. "rules": rules,
  4608. "region": region,
  4609. "callbackUrl": callback_url,
  4610. "callbackToken": callback_token,
  4611. "repeatAlarmCycle": repeat_alarm_cycle,
  4612. "maxRepeatCount": max_repeat_count,
  4613. "tag": tag
  4614. }
  4615. return self._send_csm_request(http_methods.PUT, path, body=json.dumps(body))
  4616. def list_custom_policy(self, user_id, page_no, page_size, alarm_name=None, namespace=None, action_enabled=None):
  4617. """
  4618. :param user_id:
  4619. :type user_id: string
  4620. :param page_no: page number
  4621. :type page_no: int
  4622. :param page_size: page size
  4623. :type page_size: int
  4624. :param alarm_name: alarm name
  4625. :type alarm_name: string
  4626. :param namespace: namespace
  4627. :type namespace: string
  4628. :param action_enabled: is action enabled
  4629. :type action_enabled: bool
  4630. :return
  4631. :rtype baidubce.bce_response.BceResponse
  4632. """
  4633. params = {
  4634. b'pageNo': page_no,
  4635. b'pageSize': page_size,
  4636. b'userId': user_id,
  4637. b'alarmName': alarm_name,
  4638. b'actionEnabled': action_enabled,
  4639. b'namespace': namespace
  4640. }
  4641. path = b'/custom/alarm/configs/list'
  4642. return self._send_csm_request(http_methods.GET, path, params=params)
  4643. def detail_custom_policy(self, user_id, namespace, alarm_name):
  4644. """
  4645. :param user_id:
  4646. :type user_id: string
  4647. :param namespace: namespace
  4648. :type namespace: string
  4649. :param alarm_name: alarm name
  4650. :type alarm_name: string
  4651. :return: Returns detailed information about a custom policy.
  4652. :rtype: baidubce.bce_response.BceResponse
  4653. """
  4654. params = {
  4655. b'userId': user_id,
  4656. b'alarmName': alarm_name,
  4657. b'namespace': namespace
  4658. }
  4659. path = b'/custom/alarm/configs/detail'
  4660. return self._send_csm_request(http_methods.GET, path, params=params)
  4661. def block_custom_policy(self, user_id, namespace, alarm_name):
  4662. """
  4663. :param user_id: User's identifier
  4664. :type user_id: string
  4665. :param namespace: Namespace
  4666. :type namespace: string
  4667. :param alarm_name: Alarm name
  4668. :type alarm_name: string
  4669. :return:
  4670. :rtype: baidubce.bce_response.BceResponse
  4671. """
  4672. params = {
  4673. b'userId': user_id,
  4674. b'alarmName': alarm_name,
  4675. b'namespace': namespace
  4676. }
  4677. path = b'/custom/alarm/configs/block'
  4678. return self._send_csm_request(http_methods.POST, path, params=params)
  4679. def unblock_custom_policy(self, user_id, namespace, alarm_name):
  4680. """
  4681. :param user_id: User's identifier
  4682. :type user_id: str
  4683. :param namespace: Namespace
  4684. :type namespace: str
  4685. :param alarm_name: Alarm name
  4686. :type alarm_name: str
  4687. :return:
  4688. :rtype: baidubce.bce_response.BceResponse
  4689. """
  4690. params = {
  4691. b'userId': user_id,
  4692. b'alarmName': alarm_name,
  4693. b'namespace': namespace
  4694. }
  4695. path = b'/custom/alarm/configs/unblock'
  4696. return self._send_csm_request(http_methods.POST, path, params=params)
  4697. def create_site_once_task(self, site_once_type, user_id, address, idc, timeout, protocol_type, once_config,
  4698. task_type="NET_QUAILTY", ip_type="ipv4", advanced_flag=False,
  4699. advanced_config=None, group_id=None):
  4700. """
  4701. :param site_once_type: Type of site
  4702. :type site_once_type: str
  4703. :param user_id: User's identifier
  4704. :type user_id: str
  4705. :param address: Address
  4706. :type address: str
  4707. :param idc: IDC
  4708. :type idc: str
  4709. :param timeout: Timeout
  4710. :type timeout: int
  4711. :param protocol_type: Protocol type
  4712. :type protocol_type: str
  4713. :param once_config: Configuration for once
  4714. :type once_config: dict
  4715. :param task_type: Task type
  4716. :type task_type: str
  4717. :param ip_type: IP type
  4718. :type ip_type: str
  4719. :param advanced_flag: Advanced flag
  4720. :type advanced_flag: bool
  4721. :param advanced_config: Advanced configuration
  4722. :type advanced_config: dict
  4723. :param group_id: Group identifier
  4724. :type group_id: str
  4725. :return:
  4726. :rtype: baidubce.bce_response.BceResponse
  4727. """
  4728. types = ["HTTP", "HTTPS", "PING", "FTP", "TCP", "UDP", "DNS"]
  4729. if site_once_type is not None and site_once_type not in types:
  4730. raise ValueError('site_once_type must be none or one of %s' % str(types))
  4731. path = (b'/site/once/%s/taskCreate' % compat.convert_to_bytes(site_once_type))
  4732. if advanced_config is None:
  4733. advanced_config = {}
  4734. body = {
  4735. "userId": user_id,
  4736. "address": address,
  4737. "idc": idc,
  4738. "timeout": timeout,
  4739. "protocolType": protocol_type,
  4740. "onceConfig": once_config,
  4741. "taskType": task_type,
  4742. "ipType": ip_type,
  4743. "advancedFlag": advanced_flag,
  4744. "advancedConfig": advanced_config,
  4745. "groupId": group_id
  4746. }
  4747. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
  4748. def list_site_once_records(self, user_id=None, url=None, page_no=1, page_size=10,
  4749. order=None, order_by=None, group_id=None):
  4750. """
  4751. :param user_id: User's identifier, defaults to None
  4752. :type user_id: str
  4753. :param url: URL
  4754. :type url: str
  4755. :param page_no: Page number
  4756. :type page_no: int
  4757. :param page_size: Page size
  4758. :type page_size: int
  4759. :param order: Order
  4760. :type order: str
  4761. :param order_by: Order by
  4762. :type order_by: str
  4763. :param group_id: Group identifier
  4764. :type group_id: str
  4765. :return:
  4766. :rtype: baidubce.bce_response.BceResponse
  4767. """
  4768. path = b'/site/once/taskList'
  4769. body = {
  4770. "userId": user_id,
  4771. "url": url,
  4772. "pageNo": page_no,
  4773. "pageSize": page_size,
  4774. "order": order,
  4775. "orderBy": order_by,
  4776. "groupId": group_id
  4777. }
  4778. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
  4779. def delete_site_once_record(self, user_id, site_id):
  4780. """
  4781. :param user_id: User's identifier
  4782. :type user_id: str
  4783. :param site_id: Site identifier
  4784. :type site_id: str
  4785. :return:
  4786. :rtype: baidubce.bce_response.BceResponse
  4787. """
  4788. path = b'/site/once/taskDelete'
  4789. body = {
  4790. "userId": user_id,
  4791. "siteId": site_id,
  4792. }
  4793. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
  4794. def detail_site_once_result(self, user_id, site_id, page_no=1, page_size=10, order=None, order_by=None,
  4795. filter_area=None, filter_isp=None):
  4796. """
  4797. :param user_id: User's identifier
  4798. :type user_id: str
  4799. :param site_id: Site identifier
  4800. :type site_id: str
  4801. :param page_no: Page number
  4802. :type page_no: int
  4803. :param page_size: Page size
  4804. :type page_size: int
  4805. :param order: Order
  4806. :type order: str
  4807. :param order_by: Order by
  4808. :type order_by: str
  4809. :param filter_area: Filter area
  4810. :type filter_area: str
  4811. :param filter_isp: Filter ISP
  4812. :type filter_isp: str
  4813. :return:
  4814. :rtype: baidubce.bce_response.BceResponse
  4815. """
  4816. path = b'/site/once/loadData'
  4817. body = {
  4818. "userId": user_id,
  4819. "siteId": site_id,
  4820. "pageNo": page_no,
  4821. "pageSize": page_size,
  4822. "order": order,
  4823. "orderBy": order_by,
  4824. "filterArea": filter_area,
  4825. "filterIsp": filter_isp
  4826. }
  4827. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
  4828. def detail_site_once(self, user_id, site_id=None, site_ids=None, group_id=None, page_no=1, page_size=10,
  4829. order=None, order_by=None, filter_area=None, filter_isp=None):
  4830. """
  4831. :param user_id: User's identifier
  4832. :type user_id: str
  4833. :param site_id: Site identifier
  4834. :type site_id: str
  4835. :param site_ids: List of site identifiers
  4836. :type site_ids: list
  4837. :param group_id: Group identifier
  4838. :type group_id: str
  4839. :param page_no: Page number
  4840. :type page_no: int
  4841. :param page_size: Page size
  4842. :type page_size: int
  4843. :param order: Order
  4844. :type order: str
  4845. :param order_by: Order by
  4846. :type order_by: str
  4847. :param filter_area: Filter area
  4848. :type filter_area: str
  4849. :param filter_isp: Filter ISP
  4850. :type filter_isp: str
  4851. :return:
  4852. :rtype: baidubce.bce_response.BceResponse
  4853. """
  4854. path = b'/site/once/groupTask'
  4855. body = {
  4856. "userId": user_id,
  4857. "siteId": site_id,
  4858. "siteIds": site_ids,
  4859. "groupId": group_id,
  4860. "pageNo": page_no,
  4861. "pageSize": page_size,
  4862. "order": order,
  4863. "orderBy": order_by,
  4864. "filterArea": filter_area,
  4865. "filterIsp": filter_isp
  4866. }
  4867. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
  4868. def again_exec_site_once(self, user_id, site_id):
  4869. """
  4870. :param user_id: User's identifier
  4871. :type user_id: str
  4872. :param site_id: Site identifier
  4873. :type site_id: str
  4874. :return:
  4875. :rtype: baidubce.bce_response.BceResponse
  4876. """
  4877. path = b'/site/once/createFromTask'
  4878. body = {
  4879. "userId": user_id,
  4880. "siteId": site_id
  4881. }
  4882. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
  4883. def list_site_once_history(self, user_id="", site_id="", group_id=""):
  4884. """
  4885. :param user_id: User's identifier
  4886. :type user_id: str
  4887. :param site_id: Site identifier
  4888. :type site_id: str
  4889. :param group_id: group identifier
  4890. :type group_id: str
  4891. :return:
  4892. :rtype: baidubce.bce_response.BceResponse
  4893. """
  4894. path = b'/site/once/groupTaskList'
  4895. body = {
  4896. "userId": user_id,
  4897. "groupId": group_id,
  4898. "siteId": site_id
  4899. }
  4900. return self._send_csm_request(http_methods.POST, path, body=json.dumps(body))
  4901. def get_site_once_agent(self, user_id, ip_type="ipv4"):
  4902. """
  4903. :param user_id: User's identifier
  4904. :type user_id: str
  4905. :param ip_type: the type of ip, enum: ipv4, ipv6
  4906. :type ip_type: str
  4907. :return:
  4908. :rtype: baidubce.bce_response.BceResponse
  4909. """
  4910. types = ["ipv4", "ipv6"]
  4911. if ip_type is not None and ip_type not in types:
  4912. raise ValueError('ip_type must be none or one of %s' % str(types))
  4913. params = {
  4914. b'userId': user_id,
  4915. b'ipType': ip_type,
  4916. }
  4917. path = b'/site/once/siteAgent'
  4918. return self._send_csm_request(http_methods.GET, path, params=params)
  4919. @required(user_id=str, scope=str, region=str, resource_type=str, dimensions=list,
  4920. metric_names=list, timestamp=str, statistics=list, cycle=int)
  4921. def get_multi_dimension_latest_metrics(self, user_id, scope, region=None, resource_type=None, dimensions=None,
  4922. metric_names=None, timestamp=None, statistics=None, cycle=None):
  4923. """
  4924. :param user_id: str
  4925. :param scope: str
  4926. :param region: str
  4927. :param resource_type: str
  4928. :param dimensions: list
  4929. :param metric_names: list
  4930. :param timestamp: str
  4931. :param statistics: list
  4932. :param cycle: int
  4933. :return:
  4934. """
  4935. if len(user_id) <= 0:
  4936. raise ValueError("user_id should not be null")
  4937. if len(scope) <= 0:
  4938. raise ValueError("scope should not be null")
  4939. if metric_names is None:
  4940. raise ValueError("metric_names should not be null")
  4941. if len(dimensions) > MAX_INSTANCE_NUMBER:
  4942. raise ValueError("dimensions size cannot more than " + MAX_INSTANCE_NUMBER)
  4943. if cycle is None:
  4944. cycle = 60
  4945. body = {
  4946. "userId": user_id,
  4947. "scope": scope,
  4948. "cycle": cycle
  4949. }
  4950. metric_names_req = []
  4951. for res in metric_names:
  4952. metric_names_req.append(res)
  4953. body["metricNames"] = metric_names_req
  4954. if region is not None:
  4955. body["region"] = region
  4956. if resource_type is not None:
  4957. body["resourceType"] = resource_type
  4958. if dimensions is not None:
  4959. dimensions_res = []
  4960. for res in dimensions:
  4961. dimensions_res.append(res)
  4962. body["dimensions"] = dimensions_res
  4963. if timestamp is not None:
  4964. body["timestamp"] = timestamp
  4965. if statistics is not None:
  4966. body["statistics"] = statistics
  4967. user_id = compat.convert_to_bytes(user_id)
  4968. scope = compat.convert_to_bytes(scope)
  4969. path = b'/userId/%s/services/%s/data/metricData/latest/batch' % (user_id, scope)
  4970. return self._send_csm_request(http_methods.POST, path, version=b'/v2', body=json.dumps(body))
  4971. def get_metrics_by_partial_dimensions(self, user_id, scope, statistics, metric_name, start_time, end_time,
  4972. region=None, resource_type=None, dimensions=None, cycle=None,
  4973. pageNo=None, pageSize=None):
  4974. """
  4975. :param user_id: str
  4976. :param scope: str
  4977. :param statistics: list
  4978. :param metric_name: str
  4979. :param start_time: str
  4980. :param end_time: str
  4981. :param region: str
  4982. :param resource_type: str
  4983. :param dimensions: list
  4984. :param cycle: int
  4985. :param pageNo: int
  4986. :param pageSize: int
  4987. :return:
  4988. """
  4989. if len(user_id) <= 0:
  4990. raise ValueError("user_id should not be null")
  4991. if len(scope) <= 0:
  4992. raise ValueError("scope should not be null")
  4993. if len(metric_name) <= 0:
  4994. raise ValueError("metric_name should not be null")
  4995. if len(start_time) <= 0:
  4996. raise ValueError("start_time should not be null")
  4997. if len(end_time) <= 0:
  4998. raise ValueError("end_time should not be null")
  4999. if len(statistics) <= 0:
  5000. raise ValueError("statistics should not be null")
  5001. if len(dimensions) > MAX_INSTANCE_NUMBER:
  5002. raise ValueError("dimensions size cannot more than " + MAX_INSTANCE_NUMBER)
  5003. body = {
  5004. "userId": user_id,
  5005. "scope": scope,
  5006. "startTime": start_time,
  5007. "endTime": end_time,
  5008. "statistics": statistics,
  5009. "metricName": metric_name
  5010. }
  5011. if region is not None:
  5012. body["region"] = region
  5013. if resource_type is not None:
  5014. body["resourceType"] = resource_type
  5015. if dimensions is not None:
  5016. dimensions_res = []
  5017. for res in dimensions:
  5018. dimensions_res.append(res)
  5019. body["dimensions"] = dimensions_res
  5020. if cycle is not None:
  5021. body["cycle"] = cycle
  5022. if pageNo is not None:
  5023. body["pageNo"] = pageNo
  5024. if pageSize is not None:
  5025. body["pageSize"] = pageSize
  5026. user_id = compat.convert_to_bytes(user_id)
  5027. scope = compat.convert_to_bytes(scope)
  5028. path = b'/userId/%s/services/%s/data/metricData/PartialDimension' % (user_id, scope)
  5029. return self._send_csm_request(http_methods.POST, path, version=b'/v2', body=json.dumps(body))
  5030. def get_all_data_metrics_v2(self, user_id, scope, region, dimensions, metric_names, statistics,
  5031. start_time, end_time, type="Instance", cycle=60):
  5032. """
  5033. :param user_id: user_id
  5034. :type string
  5035. :param scope: scope
  5036. :type string
  5037. :param region: region
  5038. :type string
  5039. :param type: resource type
  5040. :type string
  5041. :param dimensions: dimensions
  5042. :type double string array
  5043. :param metric_names: metric names
  5044. :type string array
  5045. :param statistics: statistics
  5046. :type string array
  5047. :param cycle: cycle
  5048. :type int
  5049. :param start_time: start time
  5050. :type string
  5051. :param end_time: end time
  5052. :type string
  5053. :return:
  5054. """
  5055. if len(user_id) <= 0:
  5056. raise ValueError("user_id should not be null")
  5057. if len(scope) <= 0:
  5058. raise ValueError("scope should not be null")
  5059. if len(region) <= 0:
  5060. raise ValueError("region should not be null")
  5061. if metric_names is None:
  5062. raise ValueError("metric_names should not be null")
  5063. if dimensions is None:
  5064. raise ValueError("dimensions should not be null")
  5065. if statistics is None:
  5066. raise ValueError("statistics should not be null")
  5067. if len(dimensions) > MAX_INSTANCE_NUMBER:
  5068. raise ValueError("dimensions size cannot more than " + MAX_INSTANCE_NUMBER)
  5069. body = {
  5070. "userId": user_id,
  5071. "scope": scope,
  5072. "cycle": cycle,
  5073. "region": region,
  5074. "startTime": start_time,
  5075. "endTime": end_time,
  5076. "metricNames": metric_names,
  5077. "dimensions": dimensions,
  5078. "statistics": statistics
  5079. }
  5080. if type is not None:
  5081. body["type"] = type
  5082. path = b'/data/metricAllData'
  5083. return self._send_csm_request(http_methods.POST, path, version=b'/v2', body=json.dumps(body))
  5084. def batch_get_all_data_metrics_v2(self, user_id, scope, region, dimensions, metric_names, statistics,
  5085. start_time, end_time, type="Instance", cycle=60):
  5086. """
  5087. :param user_id: user_id
  5088. :type string
  5089. :param scope: scope
  5090. :type string
  5091. :param region: region
  5092. :type string
  5093. :param dimensions: dimensions
  5094. :type double dimensional dict array
  5095. :param metric_names: metric names
  5096. :type string array
  5097. :param statistics: statistics
  5098. :type string array
  5099. :param start_time: start time
  5100. :type string
  5101. :param end_time: end time
  5102. :type string
  5103. :param type: type
  5104. :type string
  5105. :param cycle: cycle
  5106. :type int
  5107. :return:
  5108. """
  5109. if len(user_id) <= 0:
  5110. raise ValueError("user_id should not be null")
  5111. if len(scope) <= 0:
  5112. raise ValueError("scope should not be null")
  5113. if len(region) <= 0:
  5114. raise ValueError("region should not be null")
  5115. if len(metric_names) <= 0:
  5116. raise ValueError("metric_names should not be null")
  5117. if len(dimensions) <= 0:
  5118. raise ValueError("dimensions should not be null")
  5119. if len(statistics) <= 0:
  5120. raise ValueError("statistics should not be null")
  5121. if len(dimensions) > MAX_INSTANCE_NUMBER:
  5122. raise ValueError("dimensions size cannot more than " + MAX_INSTANCE_NUMBER)
  5123. body = {
  5124. "userId": user_id,
  5125. "scope": scope,
  5126. "cycle": cycle,
  5127. "region": region,
  5128. "startTime": start_time,
  5129. "endTime": end_time,
  5130. "metricNames": metric_names,
  5131. "dimensions": dimensions,
  5132. "statistics": statistics
  5133. }
  5134. if type is not None:
  5135. body["type"] = type
  5136. path = b'/data/metricAllData/batch'
  5137. return self._send_csm_request(http_methods.POST, path, version=b'/v2', body=json.dumps(body))
  5138. def get_metric_dimension_top(self, user_id, scope, region, dimensions, metric_name, statistics, labels,
  5139. start_time, end_time, order="top", topNum=10):
  5140. """
  5141. :param user_id: user_id
  5142. :type string
  5143. :param scope: scope
  5144. :type string
  5145. :param region: region
  5146. :type string
  5147. :param dimensions: dimensions
  5148. :type map
  5149. :param metric_name: metric_name
  5150. :type string
  5151. :param statistics: statistics
  5152. :type string
  5153. :param labels: labels
  5154. :type set
  5155. :param start_time: start_time
  5156. :type string
  5157. :param end_time: end_time
  5158. :type string
  5159. :param order: order default top
  5160. :type string
  5161. :param topNum: topNum default 10
  5162. :type int
  5163. :return:
  5164. """
  5165. if len(user_id) <= 0:
  5166. raise ValueError("user_id should not be null")
  5167. if len(scope) <= 0:
  5168. raise ValueError("scope should not be null")
  5169. if len(region) <= 0:
  5170. raise ValueError("region should not be null")
  5171. if len(metric_name) <= 0:
  5172. raise ValueError("metric_name should not be null")
  5173. if len(dimensions) <= 0:
  5174. raise ValueError("dimensions should not be null")
  5175. if len(labels) <= 0:
  5176. raise ValueError("lables should not be null")
  5177. if len(statistics) <= 0:
  5178. raise ValueError("statistics should not be null")
  5179. if len(start_time) <= 0:
  5180. raise ValueError("start_time should not be null")
  5181. if len(end_time) <= 0:
  5182. raise ValueError("end_time should not be null")
  5183. body = {
  5184. "userId": user_id,
  5185. "scope": scope,
  5186. "region": region,
  5187. "startTime": start_time,
  5188. "endTime": end_time,
  5189. "metricName": metric_name,
  5190. "dimensions": dimensions,
  5191. "statistics": statistics,
  5192. "labels": labels,
  5193. "order": order,
  5194. "topNum": topNum,
  5195. }
  5196. path = b'/dimensions/top'
  5197. return self._send_csm_request(http_methods.POST, path, version=b'/v2', body=json.dumps(body))